I need to use, in an Android project using Gradle, a specific artifact of a repositorty.
The artifact is kotlinx-serialization-cbor version 0.20.0 (available in the readme) from the kotlinx serialization GitHub project.
I don't know where and how to add this specific dependencies. (Probably I should add something in "gradle.build" file, the one marked as Project:YourProjectName or the one Module:app
Any help?
The README in the root of the github project explains how to add the plugins to your project. So long as your gradle install is up to date you just need to add a section at the top of your app level build.gradle like this:
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.70' // or any other kotlin plugin
id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.70'
}
In the same file make sure jcenter is included in your repositories:
repositories {
jcenter()
}
Then again in the same file add the basic library, as well as the cbor library to the dependencies:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // or "kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0" // JVM dependency
implementation "org.jetbrains.kotlinx:kotlinx-serialization-cbor:0.20.0"
}
You should probably look here https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-serialization-cbor/0.20.0 and copy-paste from Gradle/Maven etc (build system of your choice).
When building gradle I'm getting this message:
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'
I'm using Android Studio 4.1 Canary 10 and gradle:4.1.0-alpha10
It seems like the Navigation Safe Args plugin uses getApplicationIdTextResource(), so it is most likely that the error message is caused by your usage of that plugin.
You'd want to star the existing issue to ask the Safe Args plugin to use the new replacement API.
Changing to androidx.navigation:navigation-*:2.4.0-alpha02 as described here allowed a build of my app under Arctic Fox without getting the getApplicationIdTestResource warning
From the application build.gradle file:
def nav_version = "2.4.0-alpha02"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
And in the build.gradle file:
def nav_version = "2.4.0-alpha02"
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
few days i see the same issue. Then i go to ->
build.gradle file
My Dependencies before update
check the dependencies
I update the dependencies google services to 4.3.4
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.google.gms:google-services:4.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
After update
Now its working fine.
This error was for NavigationComponent for me in Android Studio Cannery 13.
So I changed the nav_version to this and My issue was solved.
ext {
*************** nav_version = "2.4.0-alpha10" ************
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-alpha13'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
and in app module build.gradle:
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
It will be solved, when 4.2.0 is stable.
From the existing issue:
Android Gradle Plugin deprecated the getApplicationIdTextResource()
API on the class BaseVariant in version 4.1.0 (see bug). The
replacement API (onVariantProperties) did not work properly for
feature libraries, so to avoid the deprecation warning, reflection was
used. That is only a short term solution, and when AGP 4.2.0 is stable
we should update to that version and remove the reflection immediately
So if you need Safe Args and do not need latest features of Gradle, keep Gradle version in Android Gradle Plugin version at 3.6.4. Once stable 4.2.0 released, update to the latest.
This error happened after i updated kotlin version to 1.7.
this was for NavigationComponent in Android Studio
So I changed the nav_version to this and My issue was solved : "2.4.0-beta02"
// Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:2.4.0-beta02"
implementation "androidx.navigation:navigation-ui-ktx:2.4.0-beta02"
For me it was because of different Kotlin versions between IDE Kotlin plugin and project_name/build.gradle file
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
"Kotlin version that is used for building with Gradle (1.3.72) differs from the one bundled into the IDE plugin (1.4.31) "
Once I made it even it started to compile again.
In my case I was using 2.3.1 version of navigation-fragment.
I just updated it to 2.4.2 and it's helped me
So, What i have done is that I have upgraded all the gradle plugins as well as dependecies versions and then run, It worked for me
I had the same problem and it was solved like this:
So I go to -> build.gradle file
My dependencies before upgrade
check the dependencies
I update Google services dependencies to latest version
dependencies {
classpath 'com.android.tools.build:gradle:(latest version)'
classpath 'com.google.gms:google-services:(latest version)'
}
Android Studio 4.1 giving the following information and It will be removed in version 5.0 of Android Gradle Plugin.
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'.
It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see TBD.
To determine what is calling BaseVariant.getApplicationIdTextResource, use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
As #ianhanniballake has pointed out, it seems likely that it's caused by the Navigation Safe Args plugin, see the existing issue, also referenced from his answer. The issue was marked as fixed on 9 November.
In terms of fixing the build error, upgrading Android Studio from 4.1.0 to 4.1.1 fixed it for me.
delete the .idea and .gradle files from the project .. it worked with me
Android studio missing classes.
The layout is blank.
Main.Activity is red letters.
[Soultion in the answer area]
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
add this line under dependencies in your build.gradle file
If Android Studio is not identifying the project as Gradle based, it means you imported the project source code from wrong directory. Try to reimport the project from a directory where you have see build.gradle file.
Follow these steps Add ConstraintLayout to your project
Or if you are using AndroidX
You need to use different build artifacts
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
Refer here for AndroidX Migrating to AndroidX
My Solution:
First,I delete Android Studio,and then Download Android Studio(include emulator and SDK) again.
Second,I change the name of my homework.
Third,I choose "Open an existing Android project".
Forth, Gradle Scripts->build.gradle->
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
}
replace
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
Done.
I have next grade
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
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 'com.google.android.material:material:1.0.0-rc01'
}
But when I want to build app I get next log:
Manifest merger failed : Attribute application#appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.
Okey! Go to manifest and do it:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.chopcode.myapplication">
<application
tools:replace="android:appComponentFactory"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
</application>
</manifest>
Then I get this error in my Logcat:
Manifest merger failed with multiple errors, see logs that I have Linked with it
I had similar problem. Added two lines in gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
These two lines automatically resolved my dependency conflicts between google's files and third party dependencies. Here's the link to follow: https://developer.android.com/topic/libraries/support-library/androidx-overview#new-project
I faced same error when i try to add Kotlin-KTX library to my project.
I try to AndroidX migration, and problem fixed!
Reason of Fail
You are using material library which is part of AndroidX.
If you are not aware of AndroidX, please go through this answer.
One app should use either AndroidX or old Android Support libraries.
That's why you faced this issue.
For example -
In your gradle, you are using
com.android.support:appcompat-v7 (Part of old --Android Support Library--)
com.google.android.material:material (Part of AndroidX) (AndroidX build artifact of com.android.support:design)
Solution
So the solution is to use either AndroidX or old Support Library. I recommend to use AndroidX, because Android will not update support libraries after version 28.0.0. See release notes of Support Library.
Just migrate to AndroidX.Here is my detailed answer to migrate to AndroidX. I am putting here the needful steps from that answer.
Before you migrate, it is strongly recommended to backup your project.
Existing project
Android Studio > Refactor Menu > Migrate to AndroidX...
It will analysis and will open Refractor window in bottom. Accept changes to be done.
New project
Put these flags in your gradle.properties
android.enableJetifier=true
android.useAndroidX=true
Check #Library mappings for equal AndroidX package.
Check #Official page of Migrate to AndroidX
What is Jetifier?
In my case, this is working perfectly..
I have added below two line codes inside manifest file
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Credit goes to this answer.
Simple Solutions - migrate into AndroidX
in the gradle.properties, just add below two scripts
android.useAndroidX=true
android.enableJetifier=true
What was the reason ↓
All packages in AndroidX live in a consistent namespace starting with the string androidx. The Support Library packages have been mapped into the corresponding androidx.* packages. For a full mapping of all the old classes and build artifacts to the new ones, see the Package Refactoring page.
Please see the Package Refactoring page
Just change "rc01" in first and last line inside dependencies to "alpha1"
This is working for me
Just remove the android.support dependancy
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
Quoting From Material Guidelines
If you don’t want to switch over to the new androidx and com.google.android.material packages yet, you can use Material Components via the com.android.support:design:28.0.0-alpha3 dependency.
Note: You should not use the com.android.support and com.google.android.dependencies in your app at the same time.
Just removing this dependency works fine
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
Here is complete dependencies example
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.0.0-beta01'
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'
}
As of Android P, the support libraries have been moved to AndroidX
Please do a refactor for your libs from this page.
https://developer.android.com/topic/libraries/support-library/refactor
See This Image and Add This line in your android AndroidManifest.xml
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Please go to Refactor->Migrate->Migrate to Android X.
Please add this to your gradle.properties file:
android.enableJetifier=true
android.useAndroidX=true
And perform Sync.
Add these lines inside in AndroidManifest.xml file.
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
just add these two lines of code to your Manifest file
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Migrate to androidX if it an existing project. If it is new project add these two flags to Gradle.propeties
android.enableJetifier=true
android.useAndroidX=true
for more detail steps https://developer.android.com/jetpack/androidx
or check this What is AndroidX?
Follow these steps:
Goto Refactor and Click Migrate to AndroidX
Click Do Refactor
Only If you don't want to use androidx
So in my case, I am using a library that was using androidx but I am not using androidx so when I downgraded that library version the problem was resolved.
In my Case:
implementation 'com.github.turing-tech:MaterialScrollBar:13.+'
the above-mentioned library makes problem 13.+ will automatically get a new version of the library which using androidx. So I downgraded library version to:
implementation 'com.github.turing-tech:MaterialScrollBar:13.2.5'
And the problem was resolved.
This issue mainly happened for old dependencies.
There have 2 solution:
First one:
Update all old dependencies and ClassPaths from Project level gradle files.
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
Second one:
Your project Migrate to AndroidX
From Android Studio Menu -> Refanctor -> Migrate to AndroidX
Thanks, let me know if anyone help from this answer.
Finally found a quick and easy solution by adding two lines in the android/build.gradle file.
googlePlayServicesVersion = "16.+"
firebaseVersion = "17.6.0"
Please follow this 100% correct.
Its all about the library versions compatibility
I was facing this strange bug couple of 2 hours.
I resolved this error by doing these steps
hange your build.gradle dependencies into
implementation 'com.google.android.gms:play-services-maps:17.0.0'
to
implementation 'com.google.android.gms:play-services-maps:15.0.0'
All I did was go to the "Refactor" option on the top menu.
Then select "Migrate to AndroidX"
Accept to save the project as a zip file.
Please update Android Studio as well as Gradle to ensure no problems are encountered.
Create new project and compare your build.gradle files and replaced all
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
and other dependencies with the same as were in a new project
someting like that
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
implementation 'androidx.core:core-ktx:1.0.0-alpha3'
And then fixed imports to use androidx in kotlin files.
If you do not intend to migrate to AndroidX follow the below steps
In terminal type gradlew app:dependencies
After dependencies are shown in the window press Ctrl+f and type androidX
You will find all the dependencies which are using androidx lib internally you may have to downgrade that or use alternative for that to ensure it is no longer using androidX libs internally.
1.Added these codes to at the end of your app/build.gradle:
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:28.0.0'
// the above lib may be old dependencies version
}
2.Modified sdk and tools version to 28:
compileSdkVersion 28
buildToolsVersion '28.0.3'
targetSdkVersion 28
3.In your AndroidManifest.xml file, you should add two line:
<application
android:name=".YourApplication"
android:appComponentFactory="AnyStrings"
tools:replace="android:appComponentFactory"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
Or Simply
Go to Refactor (Studio -> Menu -> Refactor)
Click the Migrate to AndroidX. it's working
it's working.
First of all be sure to add this line in manifest tag
xmlns:tools="https://schemas.android.com/tools"
Then add tools replace your suggested one in Android studio
Go to Refactor (Image )
Click the Migrate to AndroidX. it's working
it's working.
Try this
tools:replace="android:appComponentFactory"
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
Rebuild your project.
I had this same problem for three days.
It is like android wants us to either use Kotlin Or AndroidX, they are doing away with Android.
But this is how I solved it.
I migrated my project to AndroidX. This does not bring in any errors related to this issue in question, It updates files respectively. No method, class or variable name needs to be changed in your application.
NB: You must be using the latest Libraries (build.grudle file) in the latest stable version of android studio 3.4.1
I don't know this is the proper answer or not but it worked for me
Increase Gridle Wrapper Property
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
and Build Gridle to
classpath 'com.android.tools.build:gradle:3.4.2'
its showing error because of the version.
Change proguardFile in build.gradle (Module: app) to the following
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
instead of
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
This worked for me
For solving this issue i would recommend to define explicitly the version for the ext variables
at the android/build.gradle at your root project
ext {
googlePlayServicesVersion = "16.1.0" // default: "+"
firebaseVersion = "15.0.2" // default: "+"
// Other settings
compileSdkVersion = <Your compile SDK version> // default: 23
buildToolsVersion = "<Your build tools version>" // default: "23.0.1"
targetSdkVersion = <Your target SDK version> // default: 23
supportLibVersion = "<Your support lib version>" // default: 23.1.1
}
reference
https://github.com/zo0r/react-native-push-notification/issues/1109#issuecomment-506414941
I'm also facing the same issue,
for your android studio, you just change the android Gradle plugin version 3.3.2
and Gradle version is 5.1.1
I'm trying to add ViewModel and LiveData to a Kotlin app. I have the following dependencies added to my module's build.gradle:
implementation "android.arch.lifecycle:extensions:1.1.1"
kapt "android.arch.lifecycle:compiler:1.1.1"
testImplementation "android.arch.core:core-testing:1.1.1"
I'm given the following error:
Android dependency 'android.arch.lifecycle:runtime' has different version for the compile (1.0.0) and runtime (1.1.1) classpath. You should manually set the same version via DependencyResolution
Removing the first line (extensions) fixes the issue, indicating that the error is coming from there, but I can't figure out why.
As #RedBassett mentions Support libraries depends on this lightweight import (runtime library) as explained at android developers documentation.
This is, android.arch.lifecycle:runtime:1.0.0 is spreading up in the dependency tree as a result of an internal api (transitive) import so in my case I only had to include extensions library as "api" instead of "implementation" so that it will override its version to the highest (1.1.1).
In conclusion, change
implementation "android.arch.lifecycle:extensions:1.1.1"
to
api "android.arch.lifecycle:extensions:1.1.1"
In your main build.gradle file
allprojects {
...
configurations {
all {
resolutionStrategy {
force "android.arch.lifecycle:runtime:1.1.1"
}
}
}
}
This will enforce version 1.1.1
Apparently support-v4 was causing the conflict. In the case of this question, the Gradle dependency task wasn't working correctly, but for anyone else who runs into this issue:
./gradlew :app:dependencies will show the sub-dependencies used by your dependencies. Search the output of this command (changing app for your module name) for the dependency causing the conflict.
#RedBassett is right. However I was still having some problem excluding android.arch.lifecycle related sub dependencies.
In my case the conflict was caused in com.android.support:appcompat-v7:27.1.1.
This is how my gradle dependency looks like after excluding it.
implementation ('com.android.support:appcompat-v7:27.1.1') {
exclude group: 'android.arch.lifecycle'
}
api "android.arch.lifecycle:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"
Also, you will have to add this exclude in every imported module.
I searched for all dependencies with ./gradlew :app:dependencies as #RedBassett mentioned. I noticed the incompatible version of android.arch.core:runtime that Gradle was complaining about was stemming from my version of com.android.support:appcompat-v7, so I just updated that version to the latest and everything worked.