In a Kotlin file, I have an 'Unresolved reference: arch'.
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.OnLifecycleEvent
I have no experience in programming but I wanted to get started and learn by doing.
I am trying to replicate an Android app from this article:
https://heartbeat.fritz.ai/creating-an-android-app-with-snapchat-style-filters-in-7-steps-using-firebases-ml-kit-e79946e99688
I have Android Studio 3.3, Kotlin compiler 1.3 and Gradle 4.10.1.
I have read several threads with similar problems and I have tried:
1) Clean, Rebuild, Sync with Gradle
2) Restart computer
3) Invalidate caches and restart AS
4) Delete .idea and restart the project
5) Look for any discrepancies in plugins but to my best of knowledge I have not found them, everything is in the latest stable version.
My project build.gradle:
buildscript {
ext.kotlin_version = '1.3.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
My app build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.zqc.ml.nautilus"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-ml-vision:18.0.2'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'com.otaliastudios:cameraview:1.5.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.core:core-ktx:1.1.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
apply plugin: 'com.google.gms.google-services'
It should run properly but instead build is failed
Execution failed for task ':app:compileDebugKotlin'.
Log points to this 'Unresolved reference: arch' and nothing else.
You're using androidx artifacts, therefore the classes that used to be in android.arch.lifecycle are now in androidx.lifecycle as per the Migrating to AndroidX documentation.
Related
I am given the zipped project source code of an Android project integrated to AWS services. I need to understand and be able to add some new functionalities to the app but I cannot successfully run the project in android studio. I am using Android Studio 4.1.3.
I am new to Android and AWS and I am just learning these technologies.
How and where should I start studying the code?
Also if you could help me solve the issue I am encountering in Android Studio.
I already tried killing all gradle daemons and killing all java processes but I still encounter the same issue.
Android Studio Issue
Unable to find method 'org.gradle.api.internal.file.DefaultSourceDirectorySet.(Ljava/lang/String;Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;Lorg/gradle/api/internal/file/collections/DirectoryFileTreeFactory;)V'
org.gradle.api.internal.file.DefaultSourceDirectorySet.(Ljava/lang/String;Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;Lorg/gradle/api/internal/file/collections/DirectoryFileTreeFactory;)V
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
below is the build.gradle (project)
buildscript {
ext.kotlin_version = '1.3.31'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.9.+'
}}
allprojects {
repositories {
google()
jcenter() }}
task clean(type: Delete) {delete rootProject.buildDir}
below is the build.gradle (app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.amazonaws.appsync'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.dostcandle.ecrf"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}}
dependencies {
def lifecycle_version = "2.0.0"
def room_version = "2.2.1"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.fragment:fragment-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.amazonaws:aws-android-sdk-core:2.15.+'
kapt "androidx.room:room-compiler:$room_version"
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.jaredrummler:material-spinner:1.3.1'
implementation 'ph.ingenuity.tableview:tableview:0.1.0-alpha'
implementation 'com.amazonaws:aws-android-sdk-appsync:2.8.+'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation 'com.amazonaws:aws-android-sdk-auth-ui:2.15.+'
implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.15.+'
implementation 'com.amazonaws:aws-android-sdk-auth-userpools:2.15.+'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'}
You're using an old version of the AppSync SDK that is not compatible with Android Gradle Plugin 4.x / Gradle 6+. Right now, I see that you're using AGP 4.x.
See this GitHub issue for more details.
You have two options:
Use older versions of Gradle & Android Gradle Plugin. Specifically, 3.6.3 of the plugin, and 5.6.4 of Gradle.
Update your AppSync dependencies to at least 3.1+. See the setup notes in the project's README for more details.
Source: I authored the fix for this issue in the AppSync SDK.
apply these:
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'com.amazonaws.appsync'
instead of these:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.amazonaws.appsync'
if still it does not work then simple add these:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
Create new project most of the code should be obsolete. If you want to run existing code change jcenter() to mavenCentral() also check aws documentationhttps://aws.amazon.com/getting-started/hands-on/build-android-app-amplify/
// 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()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
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
// Add this line into `dependencies` in `buildscript`
classpath 'com.amplifyframework:amplify-tools-gradle-plugin:1.0.2'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
plugins {
id 'com.android.application'
id 'kotlin-android'
}
apply plugin: 'kotlin-kapt'
apply plugin: 'com.amplifyframework.amplifytools'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.dostcandle.ecrf"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
dataBinding true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.amplifyframework:aws-api:1.17.3'
implementation 'com.amplifyframework:aws-datastore:1.17.3'
implementation 'com.jaredrummler:material-spinner:1.3.1'
implementation 'ph.ingenuity.tableview:tableview:0.1.0-alpha'
implementation 'com.amazonaws:aws-android-sdk-appsync:2.8.+'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation 'com.amazonaws:aws-android-sdk-auth-ui:2.22.6'
implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.22.6'
implementation 'com.amazonaws:aws-android-sdk-auth-userpools:2.22.6'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
I am new to Android. I built a simple login activity (just created it) and it my project is giving this error:
ERROR: Unable to resolve dependency for ':app#debug/compileClasspath': Could not find any version that matches com.android.support:appcompat-v7:29.+.
I tried these solutions and they didnt work:
https://stackoverflow.com/questions/51218535/unable-to-resolve-dependency-for-appdebug-compileclasspath-could-not-resolv
https://stackoverflow.com/questions/47001656/unable-to-resolve-dependency-android-studio-3-0
My app gradle looks like this:
apply plugin: 'com.android.android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:29.+'
implementation 'com.android.support:design:29.+'
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'
}
This is gradle app
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.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
}
I don't understand how to resolve this issue considering I haven't even added question of my own. Please explain your solution step by step so I'm able to recreate to since this is literally the first project I created.
1 just figured out how to remove this Gradle error, follow the following steps.
Go to "File".
Click on Invalidate Cache/ Restart.
Again click on Invalidate Cache / Restart(On dialog window).
Let the Gradle build without any interruption
or
2
open the app.
go to gradle scripts.
then build.gradle(module:app)
finally inside dependecies type ( implementation 'com.android.support:appcompat-v7:27.+'
)
I deleted and reinstalled my android studio. The only thing that worked for me
When you are using
compileSdkVersion 29
buildToolsVersion "29.0.2"
Change
implementation 'com.android.support:appcompat-v7:29.+'
implementation 'com.android.support:design:29.+'
To
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
because google has changed the support libraries for androidX
in app gradle
change
apply plugin: 'com.android.android'
to
apply plugin: 'com.android.application'
I am trying to build but it gives me errors. I did research and tried following solutions but cant fix.
https://github.com/objectbox/objectbox-java/issues/386
Unable to merge dex
Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)
Error: Program type already present: androidx.versionedparcelable.ParcelImpl
Thats the error
Error: Program type already present: androidx.versionedparcelable.NonParcelField
Thats the screen
Thats my code
// 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 "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.30"
// 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
}
and this one
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.adultgaming.fantasygameapp"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:multidex:1.0.3'
//Kotlin
implementation "androidx.core:core-ktx:1.0.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.30"
//Glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
//Eventbus
implementation 'org.greenrobot:eventbus:3.1.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'
}
Please let me know if I missed something. And if want to devote let me know why.
First, check inside your gradle.properties, if you have
android.enableJetifier=true
android.useAndroidX=true
Then you do have androidx enabled.
Also, and this may be obvious, but clean your Gradle build with Build -> Clean Project
UPDATE WITH ANSWER
What is happening is one of your other libraries is using androidx, GLIDE FOR SURE, and maybe others.
You have two options...
Easy: Upgrade to androidx... Like why not? Totally worth it.
Hard: Downgrade your dependencies versions to pre androidX versions.
After I updated my Android Studio and gradle to the version 3.3.0 I can't compile my App. The views provided by the Kotlin Android Extensions doesn't work. I am having compilations errors with 'Unresolved reference: xxx' for my all views referenced.
On previously version from gradle and Android Studio my code works.
I have tried to clean and rebuild my project, invalidate caches and restart the Android Studio and create a new project and copy and paste my code to it, but all this doesn't work.
My project .gradle contains:
buildscript {
ext.kotlin_version = "1.3.20"
ext.play_sevices_version="16.0.0"
repositories {
google()
mavenCentral()
jcenter()
maven {
url "https://maven.fabric.io/public"
}
}
dependencies {
classpath "com.android.tools.build:gradle:3.3.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
classpath "com.google.gms:google-services:4.2.0"
classpath "io.fabric.tools:gradle:1.25.4"
}
}
My app .gradle contains:
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: "kotlin-kapt"
apply plugin: "com.google.gms.google-services"
apply plugin: "io.fabric"
android {
compileSdkVersion 28
defaultConfig {
....
minSdkVersion 16
targetSdkVersion 28
...
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"),
"proguard-rules.pro"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.github.StephenVinouze:KinApp:1.0.2'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-ads:17.1.3'
implementation "com.google.android.gms:play-services-maps:$play_sevices_version"
implementation "com.google.android.gms:play-services-location:$play_sevices_version"
implementation "com.google.android.gms:play-services-places:$play_sevices_version"
implementation 'com.google.android.gms:play-services-analytics:16.0.7'
implementation 'com.taskail:simple-places-search-dialog:1.0'
implementation 'com.github.duanhong169:colorpicker:1.1.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'androidx.room:room-runtime:2.1.0-alpha04'
kapt "androidx.room:room-compiler:2.1.0-alpha04"
implementation 'androidx.paging:paging-runtime:2.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'
}
Edited:
When I updated my projects dependencies, Android Studio and migrate it to use the 'androidx' some of my ids declared in layout files was deleted (I don't know why, but I think it could happened when of my actions also tried do clean the project removing unnecessary ids declaration), ids used in constraint layout wasn't deleted.
Please try as follows
File | Invalidate Caches / Restart
Deleting .idea folder
Running gradlew clean
Re-import the project
If still problem remains then just removed apply plugin: 'kotlin-android-extensions' , synchronize gradle plugin and then I added it again.
I keep getting this error when I try to build my project. I have no idea what is wrong with it and nothing I try is working.
I've trying cleaning, restarting Android Studio, and stopping the daemon with gradlew --stop.
Please help me!
Error:
Android Gradle plugin 3.0.1 must not be applied to project since version 3.0.1 was already applied to this project
Module:app script
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
apply plugin: 'com.android.library'
defaultConfig {
applicationId "com.example.joey.projectgenesis"
minSdkVersion 26
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(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.google.android.gms:play-services-ads:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:gridlayout-v7:26.1.0'
}
Project script
// 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.0.1'
// 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
}
gradle.wrapper.properties
#Fri Jan 12 20:21:58 EST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip
If you are creating just an app, remove apply plugin: 'com.android.library'.
If you are creating a library replace apply plugin: 'com.android.application' with apply plugin: 'com.android.library' and remove applicationId.
Refer this - Creating Android Libraries
My problem was much more silly. While doing find and replace, I had updated the versionCode to have a value in decimal.
Older values:
versionCode 253
versionName '2.53'
Newer values:
versionCode 2.54
versionName '2.54'
Having 2.54 for versionCode caused the issue. Changing that back to 254 did the trick for me!