I recently began using Android Studio and was trying to follow the "First App" tutorial (https://developer.android.com/training/basics/firstapp/). When I create a new project in Android Studio, however, I am almost immediately greeted by this error
ERROR: Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-5.4.1-all.zip'.
I've tried deleting my ~/.gradle directory and invalidating caches before restarting android studio but this doesn't fix the issue. I've also tried downloading gradle and using a local distribution of it, as well as playing with the version both locally and the default gradle wrapper version found in the cradle-wrapper.properties file. I tried both using the most current distribution (6.0.1) as well as going back a few versions and nothing has helped.
I am running on Mac OS 10.13.6 and Android Studio 3.5.2, using a Nougat distribution for my project (API 24, Android 7.0).
Edit: When I open the event logger, this is what I see:
11:18 Gradle sync started with single-variant sync
11:18 Gradle sync failed: ch.qos.logback.classic.Logger cannot be cast to org.gradle.api.logging.Logger (2 s 7 ms)
11:18 NDK Resolution Outcome: Project settings: Gradle model version=5.4.1, NDK version is UNKNOWN
Edit:
build.gradle files
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "eecs285.proj4.nortoncofirstapp"
minSdkVersion 24
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.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
// 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.5.2'
// 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
}
Related
I'm really frustrated. I'm new to Android development and Gradle. Last week I was able to download Android Studio and created a simple app that contains a few buttons. I had no trouble creating and running this.
This week I decided to create another, simpler app with no activities, to check whether my environment is set up properly. After a couple of days, I cannot get the IDE to build the app, and the problems appear to be Gradle-related.
Here is my gradle-wrapper.properties file:
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Here is my app-level build.gradle file:
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 16
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.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
And here is the top-level gradle.build file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
// 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
}
I read up on additional repositories that are needed, and tried inserting this code into the top-level Gradle build file:
repositories {
google()
jcenter()
maven { url "https://www.jitpack.io" }
}
}
But this does not help. When I try to build the project, I get errors saying that Gradle cannot find files (if I check the "offline" option) or when online, I see errors like this:
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all artifacts for configuration ':classpath'
In Settings, I have "Auto-detect proxy settings" checked (I'm not behind a firewall), and I'm using Gradle from the gradle-wrapper.properties file.
Given that I'm able to rebuild the app I created last week, but cannot build this new app whatever I try, I'm wondering whether file caching might be causing this trouble. I did try deleting the cached Gradle files from .gradle (I'm running on Windows 10) but that did not help. Multiple times, I have tried invalidating the cache and restarting the IDE but this does not make a difference.
I am creating a new Android Project and following are the details :-
OS : MacBook Pro (13-inch, Mid 2012) and mc OS mojave. version 10.14.6,
Android studio version 3.5
While trying to Sync the project few files are getting locked and the sync is failing. Even after deleting them and killing the gradle demon and starting the Sync again the files are locked and sync fails.
Following is the detail of the error :-
' ERROR: Timeout waiting to lock Build Output Cleanup Cache
(/Volumes/MYNEWVOLUME/study_material/android/ReadText/.gradle/buildOutputCleanup). It is
currently in use by another Gradle instance.
Owner PID: unknown
Our PID: 8524
Owner Operation: unknown
Our operation:
Lock file:
/Volumes/MYNEWVOLUME/study_material/android/ReadText/.gradle/buildOutputCleanup/buildOutputCleanup.lock
'
I found out that when I start the sync two instances of gradle demon threads starts. If I try to kill any of them then Sync fails. If i let it run then one of the thread acquires the lock and other cannot get that and hence sync fails.
Below are the gradle details :-
'
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.readtext"
minSdkVersion 15
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.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Gradle build details are
'
// 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.5.0'
// 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
}
I managed to solve the error by changing the location of my android project. Create the project in the default directory suggested by android studio and the projects run and build fine without any error. In my case I initially was creating in a different directory as shown above /Volumes/MYNEWVOLUME/study_material/android/ReadText . But again after creating a new project in the default project directory of /user/XXXX/AndroidStudioProjects/ReadText. It started running perfectly without any locks.
Issue 1: In MainActivity.java I get a syntax error 'cannot resolve symbol R'.
Issue 2: When I try to clean or rebuild the project I get a very long error linked here
It is also worth noting that I can still run the app and have it deployed to my phone. Just the option to build the app fails.
I have tried a few things including
deleting .gradle and .idea/libraries.
adding the following line
implementation 'com.android.support:support-annotations:26.1.0'
Make a project and make an app
Here are my app and MyApp Gradle files.
App Level:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "engineer.myname.myapp.myapp"
minSdkVersion 22
targetSdkVersion 26
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:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-annotations:26.1.0'
implementation 'com.android.support:design:26.1.0'
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'
}
Project Level:
// 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.3.2'
// 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
}
You have to add maven { url 'https://maven.google.com' } in repositories section.
Project Level:
// 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.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
OR
If you use version 26 then inside dependencies version should be 1.0.1 and 3.0.1 i.e., as follows
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
If you use version 27 then inside dependencies version should be 1.0.2 and 3.0.2 i.e., as follows
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
The error is with the version of Support Annotations used. It's in your error log, the last caused by line -
Caused by: org.gradle.api.GradleException: Cannot find a version of
'com.android.support:support-annotations' that satisfies the version
constraints:
Because of -
implementation 'com.android.support:support-annotations:26.1.0'
Upgrading to the latest stable version of the library will fix the problem.
Latest version as:
implementation 'com.android.support:support-annotations:28.0.0'
The need to upgrade to the latest library versions can be because of many reasons; newer Android Tools or Android Studio would require up to date libraries or one of your libraries require another library to function etc.
It is best to use the latest stable release libraries when you can. Also, consider using AndroidX libraries as older numbered versions will not be used anymore by Google in the future. Read here and here from Google Android Documentation.
This is because Android Studio tools is assuming that you're using the latest buildToolsVersion which is 28.0.3 when you're not explicitly add the buildToolsVersion to your app build.gradle like this:
android {
compileSdkVersion 26
// you didn't add any buildToolsVersion
defaultConfig {
applicationId "engineer.myname.myapp.myapp"
minSdkVersion 22
targetSdkVersion 26
...
}
...
}
So, Android Studio will implicitly adding buildToolsVersion "28.0.3":
android {
compileSdkVersion 26
buildToolsVersion "28.0.3" // added implicitly by Android Studio.
defaultConfig {
applicationId "engineer.myname.myapp.myapp"
minSdkVersion 22
targetSdkVersion 26
...
}
...
}
When you're building the app, it will gives you error 'cannot resolve symbol R' because the buildToolsVersion 28.0.3 cannot correctly working with compileSdkVersion 26 and support libraries 26.
So, you need to use the same version for buildToolsVersion, compileSdkVersion, and support libraries to avoid the problem.
Each version of the Android Gradle Plugin now has a default version of the build tools. The minimum supported version for Android Gradle Plugin 3.3.2 is 28.0.3. And probably your dependency versions, e.g. com.android.support:support-annotations:28.0.0, should match with this version in order to get rid of below error:
>Caused by: org.gradle.api.GradleException: Cannot find a version of 'com.android.support:support-annotations' that satisfies the version constraints:
Dependency path 'MyApp:app:unspecified' --> 'com.android.support:support-annotations:'
Constraint path 'MyApp' --> 'com.android.support:support-annotations' strictly '26.1.0' because of the following reason: debugRuntimeClasspath uses version 26.1.0
Here are links that may be related to your question:
https://github.com/react-native-community/react-native-camera/issues/1252#issuecomment-368249981
https://stackoverflow.com/a/52963611/8034839
I am trying to set up the Firstore API with my Android project however when I try to call FirebaseFirestore.getInstance() I get this error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.google.firebase.FirebaseApp.<clinit>(com.google.firebase:firebase-common##16.1.0:150)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore##18.1.0:70)
at ip.travelaid.backend.Database.<init>(Database.java:16)
at ip.travelaid.backend.CLITest.main(CLITest.java:11)
Caused by: java.lang.RuntimeException: Stub!
at android.os.Looper.getMainLooper(Looper.java:23)
at com.google.firebase.FirebaseApp$UiExecutor.<clinit>(com.google.firebase:firebase-common##16.1.0:987)
... 4 more
I have checked both my project and app level build.gradle files and they match what the documentation requires, even the Firebase Assistant in AS says that they are right. Just in case though here they are:
Module build.gradle:
// 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.3.2'
classpath 'com.google.gms:google-services:4.2.0'
// 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
}
App build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "ip.travelaid"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.google.firebase:firebase-firestore:18.1.0'
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'
In the Firebase Console I have set up the database to deny any read/write requests but I thought that wouldn't affect my ability to get an instance to the database.
The google-services.json file for the Firebase project is up to date, I have even tried re-downloading it from the Firebase Console to no avail.
I have tried searching for a solution online but there seem to be nothing out there on it(this could well be down to me not being able to search for the issue properly though).
Is there a setting, either in the Firebase Console or AS, that I am missing that may be causing this issue?
update compiled & target sdk like so v
compiled sdk 26
to
compiled sdk 28
Obligatory: NVM I figured it out.
The problem was that I tried to run the code from the command line and not through an Android Emulator/Device actually running the app.
When I did run it there the problem disappeared.
I noticed that Firebase APIs have upgraded from v 9.0.0 to v 9.0.1 and so decided to change that.
However it is not getting noticed.
Here is the Error in Gradle Logcat
Error:(25, 13) Failed to resolve: com.google.firebase:firebase-messaging:9.0.1
Error:(26, 13) Failed to resolve: com.google.firebase:firebase-core:9.0.1
And here are my Gradle Files
Build.Gradle-> App
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.lifeline.applicationgreat"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.firebase:firebase-messaging:9.0.1'
compile 'com.google.firebase:firebase-core:9.0.1'
}
apply plugin: 'com.google.gms.google-services'
Build.Gradle-> Project
// 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:2.1.0'
classpath 'com.google.gms:google-services:3.0.0'
// 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
}
Can Anyone tell whats the Error or if I am Missing anything.
Also Is there any requirement of Firebase-core for Cloud Messaging?
Thanks
You have to update/install Google Repository, revision 27
Check this answer: firebase setup on android
I had the same issue with "com.google.firebase:firebase-ads:9.0.1", what I did was install from de SDK Manager Google Repository Extra.
You'll need to go to the Android SDK manager and check for updates - you should see an update to the Google Play services SDK which will resolve these dependencies.
For mac os users, a part from updating your SDK, if you have installed the ADK with and without brew, be sure to check that the path for your ADK in Android studio is the correct one. My problem was that android studio reverted to the old path on its own.