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
Related
Hello I tried to run Kotlin file on Android Studio (version 4.1) and I got an error:
Kotlin library {0} was compiled with a newer Kotlin compiler and can't be read. Please update Kotlin plugin.
Even I got this error I'm able to run kotlin files but Ide don't gives me tips when I use kotlin functions and methods are marked by red colour. Kotlin version in gradle is 1.6.0, if I'm return to older version I can see tips about method names and red colour is not showed.
Gradle build(app):
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.kotlin_udemy4"
minSdkVersion 26
targetSdkVersion 31
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
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Gradle build:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.6.0"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// 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
}
Does anyon know how to resolve that issue ?
Besides Kotlin version 1.6.21 ...
That version of Android Studio appears rather outdated; eg. the current version "Chipmunk" uses:
com.android.tools.build:gradle:7.2.1
jcenter() should be replaced with mavenCentral().
And also, use JavaVersion.VERSION_11.
I have similar problem. To solve this, I do the following things:
I try to Rebuild the project, then this error log appear:
The minCompileSdk (32) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-31).
Dependency: androidx.appcompat:appcompat-resources:1.5.0.
AAR metadata file: C:\Users..........
Lower androidx.appcompat:appcompat version to 1.4.0, and then sync gradle. That's it.
Maybe you can try this way.
Next to isssue popup i selected "Details" link and there was information about expected version. Probably because I'm using older Android studio I got the problem. I updated Kotlin in gradle build to: 1.4.32 according to message.
I am facing an error:
Some Kotlin libraries attached to this project were read by a newer Kotlin compiler and can't be read. Please update Kotlin Plugin
I just created an application and started facing this error:
The Kotlin plugin shows the following:
I tried to change ext.kotlin_version:
My build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.32"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// 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
}
My build.gradle(app):
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 31
buildToolsVersion '30.0.1'
defaultConfig {
applicationId "com.yousufjamil.myj"
minSdkVersion 16
targetSdkVersion 31
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
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
I would appreciate any help. Thank You!
You need to update almost everything, I believe.
currently for Gradle we have
com.android.tools.build:gradle:7.2.1
coming to Kotlin, the current version is 1.6.21
repository jcenter() is deprecated and has been replaced by mavenCentral()
If you try to use jcenter() it will give a warning
JCenter Maven repository is no longer receiving updates: newer library versions may be available elsewhere
Also, check if there are any updates available for Android Studio.
Earlier I had the same error on Android Studio. If by changing the kotlin-version and gradle-version in the build.gradle file does not fixes the error. It might be because you have an older version and need to update the Android Studio [File -> Settings -> Appearance & Behavior -> System Settings -> Updates -> ' then Change to the latest stable version']. Later during the installation process, you would see the option to upgrade the gradle where you can choose the latest version. It worked for me. Hope it helps!
1- update the android studio by clicking the tab named help and then click "check for update" and then let the android studio be updated.
2 - restart the android studio if the error is resolved then it's well and good if not, then click on the tab "New", click on "New project" and then select project, and check the box highlighted here in the below picture.
click here to see the image
this worked for me
update android studio to the lastest version
only need to del these
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
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
}
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.