When I Upgrade Gradle from 4.2.2 to 7.3.0 I got Below Error
Cause: lateinit property _buildFeatureValues has not been initialized
So How to solve this error?
I have same error as you facing but as Andrey suggested I did build using command line and full error which I didn't get when I directly build don't know why?
But It's through error related flat dir and aar file so I did removed flat dir code and change aar file implementation code now It's started to build and my app started to install.
If you are use dagger hilt you should change your dependency as below to avoid Exception
java.lang.IllegalArgumentException: CreationExtras must have a value by SAVED_STATE_REGISTRY_OWNER_KEY error in runtime.
kapt "com.google.dagger:dagger-compiler:2.42"
kapt "com.google.dagger:hilt-android-compiler:2.43.2"
implementation "com.google.dagger:dagger:2.42"
implementation "com.google.dagger:hilt-android:2.43.2"
implementation 'androidx.hilt:hilt-work:1.0.0'
kapt "androidx.hilt:hilt-compiler:1.0.0"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation "androidx.navigation:navigation-compose:2.5.1"
Related
I am trying to migrate from Dagger2 to Hilt following the reference: https://developer.android.com/training/dependency-injection/hilt-jetpack#workmanager
But when I build my app, it fail with below error log:
/Users/.../myapp/build/tmp/kapt3/stubs/devDebug/.../MyWorker.java:13: error: incompatible types: NonExistentClass cannot be converted to Annotation
#error.NonExistentClass()
^
And here is the line 13:
line 11 #error.NonExistentClass()
line 12 public MyWorker(#org.jetbrains.annotations.NotNull()
line 13 #error.NonExistentClass()
line 14 android.content.Context appContext, #org.jetbrains.annotations.NotNull()
line 15 #error.NonExistentClass()
line 16 androidx.work.WorkerParameters params, #org.jetbrains.annotations.NotNull()
I don't know how can I fix it...
What I using versions are:
// kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.21"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.5.21"
// Hilt
implementation "com.google.dagger:hilt-android:2.35"
kapt "com.google.dagger:hilt-android-compiler:2.35"
implementation 'androidx.hilt:hilt-work:1.0.0'
kapt 'androidx.hilt:hilt-compiler:1.0.0'
// WorkManager
implementation "androidx.work:work-runtime-ktx:2.5.0"
implementation "androidx.work:work-rxjava2:2.5.0"
These versions are the latest and stable versions.
I tried to add the below Gradle setting but it's same error...
kapt {
correctErrorTypes true
}
Whooooooooo.....
I found the cause...
I'm sorry for all...
I am Korean, so I have been watching this guidance document for the Korean version: https://developer.android.com/training/dependency-injection/hilt-jetpack
But I found it is too old!
It guides to use #WorkerInject in the Korean version,
But it guides to use #AssistedInject in the English version...
When I change it, the error disappeared...
I have a relatively new project that I'm trying to build. Gradle syncs fine, but whenever I try to build, I get an error like this:
Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
> Failed to transform artifact 'common.jar (com.android.tools:common:26.4.0)' to match attributes {artifactType=android-classes, org.gradle.usage=java-runtime-jars}.
> Execution failed for JetifyTransform: C:\Users\Dave\.gradle\caches\modules-2\files-2.1\com.android.tools\common\26.4.0\539939e284fba9fe343b890a6e21c9333767c886\common-26.4.0.jar.
> Failed to transform 'C:\Users\Dave\.gradle\caches\modules-2\files-2.1\com.android.tools\common\26.4.0\539939e284fba9fe343b890a6e21c9333767c886\common-26.4.0.jar' using Jetifier. Reason: The given artifact contains a string literal with a package reference 'android.support.design.widget' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.. (Run with --stacktrace for more details.)
> Failed to transform artifact 'bundletool.jar (com.android.tools.build:bundletool:0.7.2)' to match attributes {artifactType=android-classes, org.gradle.usage=java-runtime-jars}.
> Execution failed for JetifyTransform: C:\Users\Dave\.gradle\caches\modules-2\files-2.1\com.android.tools.build\bundletool\0.7.2\31f71b66edcbe41de0268e14c961a7799a03d42a\bundletool-0.7.2.jar.
> Failed to transform 'C:\Users\Dave\.gradle\caches\modules-2\files-2.1\com.android.tools.build\bundletool\0.7.2\31f71b66edcbe41de0268e14c961a7799a03d42a\bundletool-0.7.2.jar' using Jetifier. Reason: The given artifact contains a string literal with a package reference 'android.support.design.widget' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.. (Run with --stacktrace for more details.)
I only started this project a week ago, and have been using the stable branch of Android Studio and using Gradle plugin 3.5. So, anyone have any ideas how to fix this?
What I've tried:
Disabling Jetifier in gradle.properties left me with errors about old and new databinding dependencies.
Rolling back to Gradle plugin 3.4.2 gave the same error as above.
Adding android.jetifier.blacklist = pass to gradle.properties left me with the same errors as above.
Adding android.databinding.enableV2=true to gradle.properties left me with the same errors as above.
Running the "Migrate to AndroidX" refactor in Android Studio actually left me with this weird refactor preview:
Removing apply plugin: 'kotlin-kapt' from my app-level build.gradle left me with the same errors as above.
Cleaning and rebuilding doesn't work.
Invalidating and restarting doesn't work.
EDIT 1: Gradle dependencies, for the curious... I don't think I'm using anything particularly weird here.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//Kotlin stuff
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"
//Test tools
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//UI
implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.activity:activity:1.1.0-alpha03'
//Lifecycle
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha04'
//Moshi for serialization
implementation 'com.squareup.moshi:moshi:1.8.0'
implementation 'com.squareup.moshi:moshi-kotlin:1.8.0'
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-moshi:2.6.1'
//Glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.9.0'
//Navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
implementation 'androidx.navigation:navigation-common-ktx:2.1.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'
implementation "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0"
//Diff utils
implementation group: 'io.github.java-diff-utils', name: 'java-diff-utils', version: '4.0'
//Timber for logging
implementation 'com.jakewharton.timber:timber:4.7.1'
}
Edit 2: Copy-pasted my Gradle dependencies into a new empty project and got the same errors. Could it be one of these dependencies?
Edit 3: Commenting out various libraries from my build.gradle (Moshi, Retrofit, Timber, Glide) also had no effect. So, I probably should submit a bug report to Google. Until then, what's the workaround?
Edit 4: With suggestions from the comments, I tried deleting my .gradle folder and rolling back to an earlier version of the Material design library. Both had no effect, but the latter added something interesting to the build log:
> Transform artifact kotlin-build-common.jar (org.jetbrains.kotlin:kotlin-build-common:1.3.20) with DexingNoClasspathTransform
AGPBI: {"kind":"error","text":"Invoke-customs are only supported starting with Android O (--min-api 26)","sources":[{}],"tool":"D8"}
You are not supposed to put the androidx.navigation:navigation-safe-args-gradle-plugin in your app level build.gradle. That needed to be removed.
Invoke-customs are only supported starting with Android O (--min-api 26).
This means, you'd need at least:
compileSdkVersion 26
targetSdkVersion 26
In my case i updated android studio, automatically it updated my gradle version and the build faled, returning the old version solved the problema.
I am working on Android ViewModel architecture component but I am getting the above mentioned error when trying to initialize a ViewModel in an AppCompatActivity.
import android.arch.lifecycle.ViewModelProviders;
ViewModelProviders.of(this).get(CounterViewModel.class);
There are a few questions and articles related to this, and they pointed towards adding the lifecycle:extensions and lifecycle:viewmodel dependencies in the app gradle file, but I am still getting the error.
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
The package android.arch.lifecycle does not contain the class ViewModelProviders and it only has ViewModelProvider class.
What else needs to be added to access the ViewModelProviders class?
Edit :
Dependencies in app/build.gradle:
dependencies {
implementation project(':lifecycle')
implementation project(':base')
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
}
android.arch.lifecycle:extensions:1.1.1 definitely has android.arch.lifecycle.ViewModelProviders. You can see it in Android Studio, if you open the "External Libraries" portion of the project tree and examine the library contents:
Some possible reasons for not finding the import include:
You have implementation "android.arch.lifecycle:extensions:1.1.1" in the wrong place (it should be in the dependencies closure of the module's build.gradle file, such as app/build.gradle)
You did not sync Android Studio with the Gradle build files (you are normally prompted to do this, but you can do it manually from File > Sync Project with Gradle Files from the Android Studio main menu)
You do not need both lifecycle:extensions and lifecycle:viewmodel in your build.gradle file, remove
implementation "android.arch.lifecycle:viewmodel:1.1.1"
and it should be fine now. Also, you may want to migrate to AndroidX and use the 2.0.0 versions of the library.
ViewModelProviders is now deprecated. Use ViewModelProvider instead.
If you are configuring in libary, you can modify the implementation to api
I am using Android Room Persistence library (v.1.0.0-alpha1) in my app.
Although it is working fine, when I open model class (Kotlin Data class) in Android studio, it shows Unresolved reference for all annotations used for Room database like #Entity, #ColumnInfo etc. I tried changing version of arch library to 1.0.0-alpha5 but result was same.
In Lint inspection it is showing Remove deprecated symbol import for all imported annotations.AS was not showing this error previously.
How can I resolve this issue
Edit
Following are imports I have added in my build.gradle
compile "android.arch.persistence.room:runtime:1.0.0-alpha5"
compile "android.arch.persistence.room:rxjava2:1.0.0-alpha5"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha5"
kapt "android.arch.persistence.room:compiler:1.0.0-alpha5"
Here you have an example.
https://github.com/jsperk/PocRoom
Remember, you need add:
Gradle (Project)--> maven
Gradle (Module App) dependencies -->
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
testImplementation "android.arch.persistence.room:testing:1.0.0"
implementation "android.arch.persistence.room:rxjava2:1.0.0"
In my project, I have this question cause I'm using
android.arch.lifecycle:livedata:1.1.1
than no matter using room with version 1.1.1 or 1.0.0, it still can't find the android.arch.persistence.room.Entity.
I've searched for a long time, till I found that, when I delete the LiveData implementation, the problem solved. Then I notice that, the version of these two libraries conflict. At last, I use the same version of 1.1.0 for livedata and room (since livedata have no version of 1.0.0), and solved it.
def arch_version = "1.1.0"
implementation "android.arch.persistence.room:runtime:$arch_version"
annotationProcessor "android.arch.persistence.room:compiler:$arch_version"
implementation "android.arch.persistence.room:rxjava2:$arch_version"
implementation "android.arch.persistence.room:common:$arch_version"
implementation "android.arch.lifecycle:livedata:$arch_version"
implementation "android.arch.lifecycle:extensions:$arch_version"
Adding these dependencies to your Gradle(Module App) file will solve it:-
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
testImplementation "android.arch.persistence.room:testing:1.1.1"
implementation "android.arch.persistence.room:rxjava2:1.1.1"
Why am I getting this error? My repository and Google play services are up to date and I've used all the requires steps for using Firebase like copying firebase code in both build.gradle(Project and app). The intellisence doesn't even show FirebaseAuth but displays other members of Firebase.
Solved the error by adding this to the build.gradle file(for app) -
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
The 2nd dependency is to solve the version conflict error.
Add this dependency to Gradle.Build(Module:App)
compile "com.google.firebase:firebase-auth:9.0.2"
then sync with gradle :)
Add these two dependencies into your build.gradle
as 'compile' is replaced by 'implementation'
dependencies {
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation "com.google.android.gms:play-services-gcm:16.0.0"
}
***For the latest android studio version 3.0 and new ones ***
Same problem. Clean your project with "Build"->"Clean Project".
add the following to the build.gradle (app)
implementation 'com.google.firebase:firebase-auth:9.2.1'
For me this worked with all the firebase extensions:
eg.:
Android studio adds the following line to your gradle file:
implementation 'com.google.firebase:firebase-auth:16.0.1:15.0.0'
You have to change it to:
implementation 'com.google.firebase:firebase-auth:16.0.1'
and add:
kapt 'com.google.firebase:firebase-auth:16.0.1:15.0.0'
I have android studio 3.3.1 installed. Compile is replaced with implementation. So you have to write
implementation 'com.google.firebase:firebase-auth:16.1.0'
You should replace version according to the warning you get.
on dependencies in app gradle
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
this is useful android 3.0 and onwards versions auth:16.0.1 and
core:16.0.1Firebase will work
Solved the error by adding this to the build.gradle file(for app) -
compile 'com.google.firebase:firebase-auth:9.2.1'
compile "com.google.android.gms:play-services-gcm:9.2.1"
You may need to make sure that your activity is importing the Firebase Auth module. In your .java file (eg. Login.java):
import com.google.firebase.auth.FirebaseAuth;
Please add the below line in your build.gradle file:
implementation 'com.google.firebase:firebase-auth:19.3.0'
implementation "com.google.android.gms:play-services-gcm:10.2.1"
In my case, I was using firebase-auth and firebase-messaging with different versions. So After getting an error I kept the same version for both e.g.
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
After sync, my problem was solved. try to keep the version the same for firebase libraries
implementation 'com.google.firebase:firebase-auth:16.0.1'
make sure your firebase and all the dependency are the same versions.