I am working on an android project, When I tries to add firebase dependency to project following Build error occurs. I have tried migrating to appCompat but didnt workded.
This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.The following AndroidX dependencies are detected: androidx.versionedparcelable:versionedparcelable:1.0.0, androidx.fragment:fragment:1.0.0, androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.core:core:1.0.0, androidx.customview:customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.interpolator:interpolator:1.0.0, androidx.loader:loader:1.0.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.viewpager:viewpager:1.0.0, androidx.collection:collection:1.0.0, androidx.localbroadcastmanager:localbroadcastmanager:1.0.0, androidx.lifecycle:lifecycle-common:2.0.0, androidx.arch.core:core-common:2.0.0, androidx.annotation:annotation:1.1.0, androidx.legacy:legacy-support-core-ui:1.0.0, androidx.lifecycle:lifecycle-livedata:2.0.0, androidx.lifecycle:lifecycle-viewmodel:2.0.0, androidx.lifecycle:lifecycle-livedata-core:2.0.0, androidx.arch.core:core-runtime:2.0.0, androidx.legacy:legacy-support-core-utils:1.0.0, androidx.documentfile:documentfile:1.0.0, androidx.cursoradapter:cursoradapter:1.0.0, androidx.lifecycle:lifecycle-runtime:2.0.0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclayoutinflater:1.0.0, androidx.print:print:1.0.0
dependencies added without firebase are as follows:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
Please help to resolve above issue.
android.useAndroidX=true
The Android plugin uses the appropriate AndroidX library instead of a Support Library.
android.enableJetifier=true
The Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries
Add both line in your gradle.properties file.
Then clean project and rebuild project.
May be your problem will be solved.
If not let me know.
You are currently using Android based library should be migrated to Androidx.
I suggest you migrate your project in Androidx.
You easily got more post How to migrate android to androidx my project.
Related
I am having a problem where my build cannot find one of the androidx classes, specifically:
androidx.lifecycle.DefaultLifecycleObserver
Here are my gradle deps:
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0"
implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
I don't have any other problems getting androidx classes, just this one.
I have tried to invalidate caches in android studio and restart with no luck. Also a build clean as well as a gradle sync.
I verified here:
https://developer.android.com/jetpack/androidx/migrate
The mapping of that class from the support library to androidx:
android.arch.lifecycle.DefaultLifecycleObserver ->
androidx.lifecycle.DefaultLifecycleObserver
Any ideas on why this is happening?
I think that's because you're missing one dependency:
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
Get the latest version of lifecycle-common-java8 here
See the documentation:
If you use Java 8 Language, then observe events with
DefaultLifecycleObserver. To include it you should add
"androidx.lifecycle:lifecycle-common-java8:" to your
build.gradle file.
How do I get webkit in use from androidx support library?
I have added this for example:
import androidx.webkit.WebSettings;
but it's not resolved
I have added to gradle
implementation 'androidx.appcompat:appcompat:1.0.2'
and to gradle.properties
android.enableJetifier=true
android.useAndroidX=true
I figured this out just needed to add webkit as separate dependency in gradle.
implementation 'androidx.webkit:webkit:1.0.0'
Would you know where to get the latest version for Room ?
On this Android Studio page, it is quoted that the latest Room version is 2.1.0-alpha3 but when I put this version in my build.gradle file, the project cannot compile and the following error is shown :
ERROR: Failed to resolve: android.arch.persistence.room:runtime:2.1.0-alpha3
Show in Project Structure dialog
Affected Modules: app
it is quoted that the latest Room version is 2.1.0-alpha3
It is.
when I put this version in my build.gradle file, the project cannot compile and the following error is shown
Your version is fine. Your artifact is the problem.
All new libraries are AndroidX. Your choices are:
Stick with whatever version you are using right now and keep your android.arch.persistence.room:runtime artifact and its classes, or
Migrate to AndroidX, in which case you would use androidx.room:room-runtime as the artifact, and need to change your code to reference the androidx classes for Room and everything else
The thing is, if you'r using AndroidX then the latest is 2.1.0-alpha3, or, if you are using Support libraries then it's 1.1.1 or whatever is latest and that's what mentioned in the documentation. As mentioned by CommonsWare, it's the artifact, and to find out the mappings, see this mapping documentation. And AndroidX is:
The AndroidX library contains the existing support library and also
includes the latest Jetpack components.
Example using support libraries:
dependencies {
// Other libraries...
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
}
The solution is to check AndroidX when starting a new project in Android Studio, then in the App Module Build.Gradle file the following works perfectly :
def room_version = "2.1.0-alpha03"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version" // use kapt for Kotlin
Let's say i have a public library module published to Maven Central and it is using the following dependencies:
implementation 'com.android.support:recyclerview-v7:28.0.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Will this library work with no problems on Android X based projects?
Google has released a tool called Jetifier which migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead, so your libiary should work when Jetifier is enabled.
To enable Jetifier, make sure compileSdkVersion is set to API 28 or above and add the following lines in gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
I'm building a library with jitpack.io I was able to build and compile into the application successfully, but the problem here is that in the library there includes a number of other libraries compiled into
implementation 'com.google.android.gms:play-services-ads:15.0.0'
implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'com.facebook.android:audience-network-sdk:4.99.1'
implementation 'com.appnext.sdk:banners:2.4.2.472'
implementation 'com.appnext.sdk:ads:2.4.2.472'
implementation 'com.appnext.sdk:native-ads2:2.4.2.472'
implementation 'org.jsoup:jsoup:1.11.3'
so when I compiled the library into my application and called it, it reportedly did not find the class I was including into libraries(org.jsoup., com.appnext., ..). If I want to use I have to re-declare the libraries on again in my application. Is there a way to not do this, as includes the library inside
I was facing the same issue and apparently it's a bug in maven gradle plugin v1.5; problem solved after my plugin version is updated to 2.1.
Issue: https://github.com/dcendents/android-maven-gradle-plugin/issues/61
Related Answer: https://stackoverflow.com/a/51190164/1640033