API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()' - java

I'm experiencing very annoying warning in my projects:
WARNING: API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
REASON: It is currently called from the following trace:
...
WARNING: Debugging obsolete API calls can take time during configuration. It's recommended to not keep it on at all times.
Affected Modules: app
As this warning will become an error next year I'd like to fix it once and for all.
I've updated gradle plugin, google play services plugin and all the dependencies, but issue is still there.
Here's the project-level build.gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.3.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And here's the module app build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.foo.bar"
minSdkVersion 16
targetSdkVersion 28
versionCode 9
versionName "1.08"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
//If you want to continue even if errors found use following line
abortOnError false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
...
}
apply plugin: 'com.google.gms.google-services'
As you can see, I'm not using getMergeResources() directly, so it must be one of the dependencies. I've commented out the dependencies one by one and finally had an empty dependencies list. However, warning was still thrown. Then I figured out that commenting out apply plugin: 'com.google.gms.google-services' fixes the issue. But I use the latest google services plugin and I obviously cannot use anything firebase related without it.
How can I fix this? I don't like downgrading gradle plugin as it's only a temporary fix.

Two versions of the Google Services Gradle Plugin (4.3.0 & 4.3.1) are causing this, upgrading the version to 4.3.2 seems to solve the issue;
In your project-level build.gradle file, under buildscript -> dependencies, check whether you have this line
classpath 'com.google.gms:google-services:4.3.x'
if so, change it to
classpath 'com.google.gms:google-services:4.3.3'
Edit: Click here to check the newest version. (4.3.3) at time of Edit.

Is a known issue, will be fixed on the next release:
https://github.com/google/play-services-plugins/issues/65
https://github.com/google/play-services-plugins/pull/62

Please change your classpath dependency in project level Gradle:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
}
}
I am using it. It is working fine. This is a stable version. Hope this issue will be fixed in the future version of this dependency.

Related

Android Studio 2022 Gradle Problems

it's been 3 days I'm struggling with this problem and didn't find a single solution to this.
Everything was good I had many projects in android studio 2022 working well but suddenly it seems all of my Gradle files are changed ?! or they are just I don't know what happened to them they are broken! every single project I open even the new project gives me an error in every single dependency or plugin ill share the information about it below here:
Every single Build.Gradle (Project) File :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
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
}
Sample build.Gradle (App)
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.teach.mytest"
minSdk 28
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
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
** Sample gradle-wrapper.properties:**
distributionBase=GRADLE_USER_HOME
distributionUrl=https://services.gradle.org/distributions/gradle-7.6-rc-1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
** Sample settings.gradle: **
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "MyTest"
include ':app'
Errors:
simple explaining about errors The errors are simply coming for all the projects are the same but when one project has extra dependency it gets errors like the below too for that dependency
also when I change the Gradle version from properties it's downloading the new Gradle working well but in the build phase it gives the same errors
Plugin [id: 'com.android.application', version: '7.2.2', apply: false] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:7.2.2')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo
** Whatever i did ?**
I tried to create a new project
I tried to change the java version
I tried to change the Gradle version and the application version
I tried to invalidate caches and restart
** Notes **
I'm using Java 15 mainly in my projects default android studio java version is 11
I change it via setting > build tool
But the problem is same also same in kotlin projects
Edit:
I changed the android.application version to 7.0.0
everything downloaded started from scratch at the final part its giving only error for gradle version 7.0.0

Android Studio - Error Module not specified

i'm a newbie to Android/Java development and purchased a book Java Programming for Android Developers For Dummies, 2nd Edition.
This comes with a code samples section http://users.drew.edu/bburd/Java4Android/ (chapter 02_01) I understand the book is a few years old hence so the code samples will be. However, i'm having massive problems getting the code samples to run on Android Studio 4.1.2.
I can import the project and sync the Gradle files. When I do it appears with a green tick at the bottom. Oddly it says failed next to that with the following message.
Gradle sync failed: Unsupported method: SyncIssue.getMultiLineMessage().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
Consult IDE log for more details (Help | Show Log) (1 s 443 ms)
My build.gradle file is as follows
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
// 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
}
Also if I try and run the project I see this screen
I've read many posts with similar issues and worked through various fixes. None seemed to work so can anyone shed any light on what's happening please? I've also downloaded android studio on 3 different PC's incase its a bug of some sort.
Thank you
I should say the files in there are very outdated, and you will have very hard time, with every project. But if you still want to build the project here are a few things you can do.
look for the file gradle-wrapper.properties and update it with this
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
Then move to project level build.gradle file (there are two one inside app directory and one on the root directory, use the root directory)
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Then move to app level build.gradle and update it with this
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.allyourcode.a02_01"
minSdkVersion 15
targetSdkVersion 30
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'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
testImplementation 'junit:junit:4.13.1'
}
And then sync the project and let Android studio do its magic.
As the stack traces say, you should upgrade your Gradle version. You are using an "old" book where the samples have been build with an old version of Android Studio that supports well that old version of Gradle. But 4.1 is a recent version and does not support well many old Gradle features.

Error after adding Facebook login dependency in Android

I want to integrate my app with facebook login, but when adding below dependency and syncing Gradle:
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
I got the following errors:
ERROR: Failed to resolve: legacy-support-v4
Affected Modules: app
ERROR: Failed to resolve: browser
Affected Modules: app
ERROR: Failed to resolve: legacy-support-core-utils
Affected Modules: app
ERROR: Failed to resolve: media
Affected Modules: app
My build.gradle in app-level:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
}
repositories { }
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.***************"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.github.GrenderG:Toasty:1.4.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.gauravk.bubblenavigation:bubblenavigation:1.0.7'
implementation 'com.tuyenmonkey:mkloader:1.4.0'
implementation 'me.riddhimanadib.form-master:form-master:1.1.0'
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
}
apply plugin: 'com.google.gms.google-services'
and build.gradle on project-level:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.31.2'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://www.jitpack.io" }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I've searched a lot on google and StackOverflow and tested all the methods, but this problem doesn't fix. Please help me where is my problem.
First of all remove
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/'}
}
}
repositories { }
from your app-level Gradle file when you have repositories set in your project-level Gradle file. This causes confusion.
Use implementation 'com.facebook.android:facebook-android-sdk:5.13.0' instead of your dependency.
You can always check Maven Centeral for the latest version of libraries.
or
Use Gradle, please, just enter the library name you need and copy the result (don't forget to replace compile with implementation)
I've tested some of Facebook SDK versions, suddenly in 4.26.0 version, my Gradle was successfully built.
I've checked the release note of Facebook SDK on the next version ( 4.27.0 ) and I find this:
Modified
+ Restructured the Facebook SDK and organized it into separate libraries/modules that can depend on one another.
+ Moves GraphRequest.createOpenGraphObject(ShareOpenGraphObject) to ShareGraphRequest.createOpenGraphObject(ShareOpenGraphObject)
+ Moves FacebookSDK.[set|get]WebDialogTheme(...) to WebDialog.[set|get]WebDialogTheme(...)
+ Removes unused dimens from styles.xml
+ Removes files only used by internal tests
+ updates proguard files
Anyway, with the following line, my problem was solved:
implementation 'com.facebook.android:facebook-android-sdk:4.26.0'
It's not good news for me to use about 3 years ago package, but at this point, I don't have any Idea.
Looks like you're pointing to a library that doesn't exist.
Replace your implementation.... with:
implementation 'com.facebook.android:facebook-login:[5,6)'
(source: https://developers.facebook.com/docs/android/componentsdks/)
As Stated in this post, you need to add these two properties to gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true

getting red line in files after upgrading to gradle 4.4 and gradle build tools version 3.1.2

The Android studio ask me to update the gradle version to 4.4 and gradle build tool version to 3.1.2.
After the update, The whole android studio shows red lines in file, when I hover my cursor on these error it says "cannot resolve symbol" but compiles with no error i.e., build is successful.Click here to see red lines in java files
and Here are the gradle app and project files.
//Build.gradle(project)
//Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven {
url 'https://maven.fabric.io/public'
}
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.0'
classpath 'io.fabric.tools:gradle:1.25.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
url 'https://maven.google.com/'
}
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and
//build.gradle(module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.developers.paras.droidwatch"
minSdkVersion 19
targetSdkVersion 27
versionCode 9
versionName "9.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
android.defaultConfig.vectorDrawables.useSupportLibrary = true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support:customtabs:27.1.1'
compile 'com.android.support.constraint:constraint-layout:1.1.0'
compile 'com.android.support:design:27.1.1'
compile 'com.android.support:support-v4:27.1.1'
compile 'com.google.android.gms:play-services-ads:15.0.1'
compile 'com.google.firebase:firebase-core:15.0.2'
compile 'com.crashlytics.sdk.android:crashlytics:2.9.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
Things I have already tried.
Clean and Rebuild.
Invalidate Cache and Restart.
Updating gradle version to 4.9.
Setting local gradle for the project.
See my gradle logs here https://drive.google.com/open?id=18bFZdkWX4AFPfpmfjvN1t80WpVRpiHWs
See even release build is generated after these errors. Release apk generated
Update : Recently after Reinstalling Studio, I've created a new project and everything works fine. No errors for "cannot resolve symbol".
not the most graceful solution in the world but deleting and re-cloning the project was the fastest way to resolve this for me.
if you're not using git... well. now is a good time to start.
I tried deleting and re-syncing all the various config files and it didn't do anything.
I got into similar situation: upgraded Gradle to 4.4, then opened a former porject which had been built with Gradle 3.1.2.
Android Studio noticed it and generously offered:
To take advantage of all the latest features (such as Instant Run), improvements and security fixes, we strongly recommend that you update the Android Gradle plugin to version 3.1.2 and Gradle to version 4.4.
When I choose to update, I got the red underlines showing errors everywhere in MainActivity.java, however the project was building and runnig perfectly.
I also tried to rebuild and to invalidate cache & restart, but had no success.
For me, editing the build.gradle (module:app) file helped.
When I modified both compileSdkVersion and targetSdkVersion to the latest (27) and changed the version number of line implementation 'com.android.support:appcompat-v7:2x.x.x' under dependencies to the latest, then resynced, the red lines suddenly disappeared from MainActivity.java and everything became normal.
Maybe not the fiddling with sdk version numbers are important here, but to force a proper gradle resync.
Please note also, that since Gradle 3.4, under dependencies in build.gradle file some configuration words changed: compile, testCompile, androidTestCompile, testApi, androidTestApi become obsolete and should be replaced with implementation or api.
You can find more on this issue here: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration?utm_source=android-studio#new_configurations and a proper explanation on the difference between choosing implementation or api here: https://medium.com/mindorks/implementation-vs-api-in-gradle-3-0-494c817a6fa

Android gradle :app:packageDebug FAILED: class org.bouncycastle.asn1.ASN1Primitive overrides final method equals

I'm new to Android and I can't get my first app to run. Whenever I try, it's throwing this error:
Android gradle :app:packageDebug FAILED: class org.bouncycastle.asn1.ASN1Primitive overrides final method equals.
I googled it and I found many questions there. As many said, this problem is probably due to the fact that I have multiple dependencies on BouncyCastle in my project. I tryed to remove the .gradle folder both in my project and in my local folder so I could download again the jars from the repository but nothing has changed. I also double checked that my JAVA_HOME is set and it's pointing to a 1.7 version. I tryed to gradle :app:clean and gradle :app:dependencies to see if I was missing something but still... I can't see any dependency from BouncyCastle... Can anybody help me?
Also, this problem occured without me changing any code... The app successfully worked yesterday and now is giving me this error... I don't get it. Thank you.
EDIT
gradle.build
Top-level:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Module app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.aurasphere.provaactionbar"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
compile project(':volley')
compile files('libs/gson-2.2.2.jar')
}
Module volley:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.+'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion = '21.1.0'
}
apply from: 'rules.gradle'
rules.gradle for module volley:
apply plugin: 'com.android.library'
I've solved this problem myself just by changing the JDK I was using from x32 to x64 and now is compiling correctly.

Categories