error: cannot find symbol class for add kotlin class into java class in android studio 3.0 stable - gradle

i use android studio 3.0 and some old java class Convert Java to Kotlin. after that Kotlin class cant import in java class!
in below you can see my gradle and a picture of my error.
module build.grade
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
in app level build.gradle in normally i use gradle code and in android 3.0 i think we need any thing
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.idehnavazan.beautifierclient"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.github.rey5137:material:1.2.2'
compile 'com.android.support:cardview-v7:25.3.1'
}
apply plugin: 'com.google.gms.google-services'

To work with Kotlin files you need to add Kotlin to your project.
project/build.gradle
buildscript {
ext.kotlinVersion = '1.1.51'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
project/module/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}
What's next
Since you're using support library 25.3.1 and Android plugin 3.0.0 your next question will probably be this: style attribute '#android:attr/windowEnterAnimation' not found.

I have added all kotlin classes in separate folder and it work for me!
Keep your java classes separate from kotlin. I was having
app:compileDebugJavaWithJavac Kotlin class calling from java: error: cannot find symbol
compile time error.

My issue was that I have imported a submodule using
testImplementation instead of implementation inside of module gradle file that is declaring your module as a dependency.
Changing the dependency declaration fixed it for me.

I am also new to kotlin/android and was using ViewBinding. I was renaming an xml-file when this type of error occured. I just added:
dataBinding {
enabled = true
}
to the build.gradle(module)-file and it now works. To be honest, I never understood the difference between view- and data-binding

kotlin/android and was using ViewBinding.
just add this inside build.gradle(module)-file
viewBinding{
enabled = true
}

Related

unresolved reference: github (cant import to my class)

I tried to download a library. But I think i did something wrong in my build.gradle Project. Because when I try to import the library manually, I get this error:
My Project Gradle File
buildscript {
repositories {
google()
maven {url 'https://jitpack.io'}
}
dependencies {
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.5.3")
}
}
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My App Gradle File
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.ahmetkaan.kediy"
minSdk 23
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
//...
implementation 'com.github.onecode369:WYSIWYG:4.0'
}
The library says me to add " maven {url 'https://jitpack.io'} " this to my project gradle and " implementation 'com.github.onecode369:WYSIWYG:4.0' " this to my app gradle. I think there is a problem in the project gradle's repositories (maven). Because the library says to me add like this;
allprojects {
repositories {
...
maven {url 'https://jitpack.io' }
}
}
But I can't add allprojects on top of repositories. I am getting an error like:
A problem occurred evaluating root project 'Kediy'.
> Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'
What should I do?

Build failed - Could not find androidx.lifecycle:compiler:2.2.0

I am totally new to Android and struggling past 2days with my build.
I get the following message
Build failed
Could not find androidx.lifecycle:compiler:2.2.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/androidx/lifecycle/compiler/2.2.0/compiler-2.2.0.pom
- https://jcenter.bintray.com/androidx/lifecycle/compiler/2.2.0/compiler-2.2.0.pom
Required by: project :app
I updated my studio and gradle plugins and versions of dependencies, but none seem to work. I am using Gradle Plugin: 4.0.1 and Gradle: 6.1.1
My project gradle is as follows
buildscript {
repositories {
google()
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And my app gradle is as follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.xxxx.xxxxxx"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha04'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
def room_version = "2.2.0"
def lifecycle_version = "2.2.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
// Saved state module for ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
// Annotation processor
annotationProcessor "androidx.lifecycle:compiler:$lifecycle_version"
// alternately - if using Java8, use the following instead of lifecycle-compiler
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// Test helpers
testImplementation "androidx.room:room-testing:$room_version"
}
In the idea.log i find the line
testKnownPluginVersionProvider - 'gradle' plugin missing from the offline Maven repo, will use default 4.0.1
repeating regularly and the gradle-wrapper properties file is as follows
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Remove the following line if you are using Java 8:
annotationProcessor "androidx.lifecycle:compiler:$lifecycle_version"

NoClassDefFoundError: error when generating apk

migrate my application to android x and gradle 5
the moment that I send to generate the apk or to install gives me this error
Caused by: java.lang.NoClassDefFoundError: com/android/tools/r8/dex/ApplicationReader
Build.graddle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
google()
}
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId "gortiz.com.goapp"
minSdkVersion 18
targetSdkVersion 28
versionCode 37
versionName '2.0.37'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true;
}
implementation 'androidx.appcompat:appcompat:1.+'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.+'
implementation 'androidx.mediarouter:mediarouter:1.+'
implementation 'androidx.core:core:1.+'
implementation 'androidx.multidex:multidex:2.+'
implementation 'com.google.android.material:material:1.+'
implementation 'commons-io:commons-io:2.5'
implementation 'androidx.constraintlayout:constraintlayout:1.+'
implementation 'androidx.legacy:legacy-support-v4:1.+'
implementation 'com.google.code.gson:gson:2.8.1'
implementation 'com.github.satyan:sugar:1.5'
implementation 'com.squareup.picasso:picasso:2.5.0'
implementation 'me.panavtec:wizard:1.2'
implementation 'com.github.johnkil.print:print:1.2.+'
implementation 'com.github.bmelnychuk:atv:1.2.+'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
testImplementation 'junit:junit:4.12'
implementation 'androidx.recyclerview:recyclerview:1.+'
implementation ('com.google.firebase:firebase-messaging:17.3.4'){
exclude group: 'com.google.firebase', module: 'firebase-iid'
}
implementation 'com.google.android.gms:play-services-maps:17.+'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.7'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.google.android.gms:play-services-gcm:16.0.0'
implementation 'com.google.android.gms:play-services-base:16.1.0'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.android.gms:play-services-vision:18.+'
implementation 'com.google.firebase:firebase-config:18.+'
implementation 'com.google.firebase:firebase-iid:17.0.2'
implementation 'androidx.annotation:annotation:1.1.0'
}
apply plugin: 'com.google.gms.google-services'
graddle.properties
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useAndroidX=true
android.enableJetifier=true
Caused by: java.lang.NoClassDefFoundError: com/android/tools/r8/dex/ApplicationReader
The top level build.gradle seems to be missing a dependency on Android Gradle Plugin. Please add something like this (depending on the version you would like to use):
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
...
}
...
}
If you create an empty project in Android Studio that should all be in place.

Unable to resolve dependency for ':app#debugUnitTest/compileClasspath', :app#debugAndroidTest/compileClasspath

Situation:
Create the simplest project
Add to the project module as File -> New -> New module "Phone & Tablet Module"
Add the dependency on the module
And get errors:
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve project :testmodule.
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve project :testmodule.
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve project :testmodule.
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve project :testmodule.
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve project :testmodule.
Below are the project files:
Project:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module: app
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.pawga.test00"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(path: ':testmodule')
}
Module: testmodule
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.pawga.testmodule"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
gradle-wrapper.properties
#Mon Jun 25 22:51:52 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
settings.gradle
include ':app', ':testmodule'
Note:
If the module type is "Android Library" (Point "two" above), then there are no such errors.
For such a simple project, where everything is by default, there should not be such errors. What's wrong?
Try this, replace:
implementation project(':testmodule')
To:
implementation project(path:':testmodule', configuration: 'default')
Go to
File -> Settings -> Build, Execution, Deployment -> Gradle menu.
You will see "Offline work" options. Uncheck it. And it's ok.
It looks like your plugin needs to be changed to apply plugin: 'com.android.library' instead of 'com.android.application'
See this post for more
information. Hope that helps.
Try online mode for gradle. Hope it helps(I had the same problem, so more chances).
##REMOVE THE FOLLOWING FROM THE BUILD GRADLE##
>>implementation 'com.android.support:appcompat-v7:28.+'
>>implementation 'com.android.support.constraint:constraint-layout:1.0.2'
>>androidTestImplementation 'com.android.support.test:runner:1.0.1'
>>androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
>>SEE ATTACHED PICTURE
>>[STUDIO ERRORS][1]
>>[1]: https://i.stack.imgur.com/DY6sz.png

gradle error Could not find method dependencyManagement()

Below is my build.gradle
buildscript {
ext {
springBootVersion = '2.0.0.M3'
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.springframework.boot'
apply plugin: 'maven-publish'
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR7'
}
}
dependencies {
compile("org.springframework.cloud:spring-cloud-starter-eureka")
compile "org.elasticsearch:elasticsearch:5.5.0"
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I was using gradle 2.14 and got the below error
> Failed to apply plugin [id 'org.springframework.boot']
> Spring Boot plugin requires Gradle 3.4 or later. The current version is Gra
dle 2.14
Then I upgraded gradle to 3.4 as suggested in the error message.
Now I get the below error
Could not find method dependencyManagement() for arguments [build_79bcact4bkf1
sckkod1j3zl7l$_run_closure1#4a2d71c9] on root project 'myproject'
of type org.gradle.api.Project.
Is the method dependencyManagement() no longer available in gradle 3.4 ?
If anybody is aware of the alternate method to be used in gradle 3.4 , kindly revert
To use this DSL you have to provide the dependency-management-plugin:
buildscript {
repositories {
maven {
jcenter() //or mavenCentral()
}
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
}
}
apply plugin: "io.spring.dependency-management"
Or you can use:
plugins {
id "io.spring.dependency-management" version "1.0.3.RELEASE"
}
More details here.
For me the fix was replacing the distributionUrl in the gradle-wrapper.properties with:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
and updating the dependencies in the build.gradle file to:
dependencies { classpath "com.android.tools.build:gradle:7.0.4" }
In Gradle 7 this error is also caused by importing a BOM using:
dependencyManagement {
imports {
mavenBom "tech.jhipster:jhipster-dependencies:${jhipsterDependenciesVersion}"
}
}
In Gradle 7 you need to import your BOM in the following way:
implementation platform("tech.jhipster:jhipster-dependencies:${jhipsterDependenciesVersion}")

Resources