How to fix gradle when this error appear? - java

I started a new project and put fire-base cloud:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "android.example.com.squawker"
minSdkVersion 16
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'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
// RecyclerView
implementation 'com.android.support:recyclerview-v7:28.0.0'
// Schematic dependencies for ContentProvider
apt 'net.simonvt.schematic:schematic-compiler:0.6.3'
implementation 'net.simonvt.schematic:schematic:0.6.3'
// Preferences Dependencies
implementation 'com.android.support:preference-v7:28.0.0'
// Firebase dependency
implementation 'com.google.firebase:firebase-messaging:17.3.4'
}
// Apply the Google Services plugin. Make sure to add the google-services.json file in the app
// folder. You download it from the Firebase console
apply plugin: 'com.google.gms.google-services'
and this error apeared:
WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getJavaCompile(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app

This probably because of apt plugin which is already obsolete. So, you need to remove the following:
apply plugin: 'android-apt'
then change the following:
apt 'net.simonvt.schematic:schematic-compiler:0.6.3'
with:
annotationProcessor 'net.simonvt.schematic:schematic-compiler:0.6.3'

Similar to API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders() Happy Coding!

Related

Can't implement firebase dependencies on my android app

i'm developing an Android Studio App and trying to create a user register activity. I already added firebase into the project but when i try to add the firebase database dependencies, the app crashes instantly and not a single error is reported. However, when i remove the 3 implements from the build gradle, it runs correctly. Here i leave both build gradle codes. Thanks.
Build gradle project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.google.gms:google-services:4.3.8'
// 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
}
Build gradle app (this works properly):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.jota02"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
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.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//new implements
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.4.0-beta01'
implementation platform('com.google.firebase:firebase-bom:28.0.1')
}
Build gradle app (this crashes):
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.jota02"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
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.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//new implements
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.4.0-beta01'
implementation platform('com.google.firebase:firebase-bom:28.0.1')
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-core:19.0.0'
implementation 'com.google.firebase:firebase-database:20.0.0'
}
SOLVED
The problem just was that i was running an old Android Studio version. I updated Android Studio and checked the gradle versions and now it's all working properly, thanks.
When you use firebase-bom dependency, you no need to mention version for firebase-database and other firebase library.
firebase-bom will choose right version for you or if you want particular version of firebase remove firebase-bom.so add dependency like below
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.0.1')
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-database'

Why android studio give an error when i add dependency?

I'm building a face detection Android app. When I add dependency inside the app/build.gradle it gives me an error. Here is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.android.emojify"
minSdkVersion 15
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'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support ', module: 'support-annotations'
})
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-vision:10.2.0'
testImplementation 'junit:junit:4.12'
}
Error is reported in the following lines:
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
Show us a screenshot of your error or format your error to easier reading, just click code button and paste it.
Edit: thank you :)
I think you should use refresh gradle after any changes in gradle.build and maybe you got this error because your build tools sdk is 28.0.3 and you want to use tool from sdk 28.0.0, just change compile sdk to 28.0.0 and click sync gradle on actionbar.
Your buildToolVersion is greater than your design and appcompat-v7.
Try to change,
implementation 'com.android.support:design:28.0.3' //or greater than 28.0.3
implementation 'com.android.support:appcompat-v7:28.0.3' //or greater than 28.0.3
connect to the internet and then build your project. Problem will be solved.

Android Studio Failed to resolve: com.android.support:appcompat-v7.28.0.0

I am getting this error, Failed to resolve: com.android.support:appcompat-v7.28.0.0 I have been looking on here and tried changing it to other variations of that line but so far no luck, why do I keep getting this error?
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 15
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'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-auth:11.6.0'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
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'
}
apply plugin: 'com.google.gms.google-services'
The issue is with the appcompat-v7 dependency that you have added to the build.gradle.
Change implementation 'com.android.support:appcompat-v7.28.0.0' to implementation 'com.android.support:appcompat-v7:28.0.0'
Notice the : between appcompat-v7 and 28.0.0 that separates the artifact name and the version.
If we don't consider the typo in :
implementation 'com.android.support:appcompat-v7.28.0.0'
Change it to:
implementation 'com.android.support:appcompat-v7:28.0.0'
Then, you probably should use the latest version for the Firebase dependencies to avoid those Please fix the version errors:
implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-database:16.0.3'
Then rebuild the project. Also, remember to use latest gradle to avoid couldn't found such dependency or etc.
Inside build.gradle of the project (inside your project root directory):
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
// replace it with the 3.2.0 version
...
classpath 'com.google.gms:google-services:4.1.0' // update this too
}

Failed to resolve: com.android.support:appcompat-v7:28.+ , Error: more than one library with package name 'android.support.graphics.drawable'

I'm new to Android Studio, I tried everything to solve this problem "Failed to resolve: com.android.support:appcompat-v7:28.+ "
I tried to clean project , invalidate cash/restart and removing .idea and still the same
I'm using android studio 2.2.1 for a learning reason , and I updated it to android studio 3 and there a multiple rendering problems so I returned back to version 2.2.1
I tried to add
maven {
url 'https://maven.google.com/'
name 'Google'
}
So,It stuck with another problem
"Error:Execution failed for task ':app:processDebugResources'.
> Error: more than one library with package name 'android.support.graphics.drawable'"
Error Photo
Finally I tried to change "appcompat-v7:28.+" to "appcompat-v7:27" and it' works but still tell me that i should use the same library to avoid mistakes
This is my Gradle code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.1"
defaultConfig {
applicationId "com.example.aimlive.myapplication"
minSdkVersion 15
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 {
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:28.+'
testCompile 'junit:junit:4.12'
}
Replace 'com.android.support:appcompat-v7:28+' by 'com.android.support:appcompat-v7:28.0.0'
and add below dependencies
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
try adding this to your code:
repositories {
jcenter()
maven { // <-- Add this
url 'https://maven.google.com/'
}
}
Update: Now you moved on to another error:
Error: more than one library with package name 'android.support.graphics.drawable ...
To fix this, you need to change compile to implementation in dependencies part.
if you are using
compileSdkVersion 28
add in your dependencies below code
implementation 'com.android.support:appcompat-v7:28.0.0-alpha'
this is the link
Try this one, hope it is working
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
dependencies
classpath 'com.android.tools.build:gradle:3.1.4'
android
compileSdkVersion 28
minSdkVersion 21
targetSdkVersion 28
Try this code, hope it will be working. Thanks
build.gradle (Project)
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
build.gradle (app)
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "YOUR_PACKAGE_NAME"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies check for implementation
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
I found that 'com.android.support:animated-vector-drawable' and 'com.android.support:support-vector-drawable' have a same package name in support library version 28.0.0. Normally this does not make the problem.
But if you have the following line in gradle.properties
android.uniquePackageNames = true
you will see the error
more than one library with package name 'android.support.graphics.drawable'"
If you should use the uniquePackageNames option, use androidx instead of support library 28.0.0.
In case someone like me stuck for hours and find out the you have to check the maven dependency "com.android.support:appcompat-v7:28.0.0". remove the "+" sign as gradle does not like it for unpredictable versions. so i had to check the maven repository and found that i was compiling with 29 and 29 does not exist. please check below link
[""][1]
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.amirkhan.birthday"
minSdkVersion 15
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 'com.android.support:appcompat-v7:28.0.0'
}
2)) Maven should be included.
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
}
Wallah the problem is solved
[1]: https://mvnrepository.com/artifact/com.android.support/appcompat-v7/28.0.0

Can't import: android.support.v7.widget.RecyclerView in Android Studio

I'm following my teachers tutorial and therefore writing exactly the same code that he has in his example. So I just created a new class to learn RecyclerView but I can't import RecyclerView On mouse-over, it just says "Cannot resolve symbol RecyclerView". I use Android Studio 2.3.3. Am I missing something obvious?
import android.support.v7.widget.RecyclerView;
public class CustomAdapter extends RecyclerView.Adapter<ComposedAdapter.Holder> {
//stuff
}
Gradle:
apply plugin: 'com.android.application'android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "sofialarsson.customrecyclerview"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
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:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
You need to add dependencies in build.gradle
Use this update gradle file
apply plugin: 'com.android.application'android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "sofialarsson.customrecyclerview"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
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.constraint:constraint-layout:1.0.2'
compile "com.android.support:appcompat-v7:25.0.0"
compile "com.android.support:recyclerview-v7:25.0.0"
testCompile 'junit:junit:4.12'
}
Add below dependency in build.gradle;
compile 'com.android.support:design:xx.x.x'
If you are using androidx artifacts, add the following to your app level build.gradle
dependencies {
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
}
Might be useful, so Let me drop this for those who might want to migrate to androidx. In your build.gradle (Module app) add the dependency like this, instead of:
compile 'com.android.support:recyclerview-v7:23.3.0'
to
implementation 'androidx.recyclerview:recyclerview:1.1.0'
Then import like this, instead of:
import android.support.v7.widget.RecyclerView;
use:
import androidx.recyclerview.widget.RecyclerView;
Sync and enjoy!
Just add these two dependencies and you are good to go.
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
Make sure always always use same versions everywhere like you use here 25.3.1.
Also update your buildToolsVersion="25.0.0" .
Thanks!!!
Just add compile 'com.android.support:recyclerview-v7:25.3.1' dependencies in build.gradle app file like below code
dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
}
Add below dependency in build.gradle
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta02'
Link Reference for latest releases
to give you an up-to-date and comprehensive answer, you have two choices.
Pre Android 9.0 (pre API 28), you have to use the old Support Library:
dependencies {
compile "com.android.support:appcompat-v7:25.0.0"
compile "com.android.support:recyclerview-v7:25.0.0"
}
For these dependencies, you have to use the version number of your Build Tools Version.
In Android 9.0 (API 28+) and above, you have to use the new Support Library (Noted here https://developer.android.com/topic/libraries/support-library/features#v7):
dependencies {
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.recyclerview:recyclerview:1.1.0"
}
For these dependencies, you have to use the version numbers from the following pages:
https://developer.android.com/jetpack/androidx/releases/appcompat
https://developer.android.com/jetpack/androidx/releases/recyclerview
Add this class in the main_activity.xml file:
class="androidx.recyclerview.widget.RecyclerView"/>
Refer to https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView
for more info...

Categories