Android Studio cannot sync and build NEW and OLD kotlin projects - android-studio

When I am creating a new project in Android Studio, and load old projects I got this:
java.lang.NoClassDefFoundError: org/gradle/internal/impldep/com/google/common/collect/Lists
java.lang.ClassNotFoundException: org.gradle.internal.impldep.com.google.common.collect.Lists
ERROR: Unable to load class 'org.gradle.internal.impldep.com.google.common.collect.Lists'.
Possible causes for this unexpected error include:
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
Now I am totally stucked with that.
1, I downloaded studio again and installed to an other drive, the probleme still exists.
2, I deleted all of my Android Studios from my computer, I downloaded and installed again. Started a new kotlin project, the same error happened.
3, invalidate/restart not fixed
4, redownload dependencies not fixed
5, update gradle not fixed
6, flutter plugin disabled, not fixed
I was used my old Android Studio for flutter/dart and kotlin too. It looks like I can not build anymore native apps/kotlin.
my gradle wrapper
distributionUrl=https://services.gradle.org/distributions/gradle-5.6.4-all.zip
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
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
}
build gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "hu.lacas.myapplication"
minSdkVersion 19
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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.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'
}
app build gradle
Any way to fix this?
Thanks

LOL. I found an old project what were built!!!
I copied this strings from that:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71"
}
and
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
and finally synced, built!!!
Something is very broken in the new Android Studio, because I got a lot of error/sync failed even if I create a NEW PROJECT

Related

Build error when trying to Run basic activity

I'm on day 1 of learning Android Studio / Kotlin and working my way through the (official?) tutorials.
Having added some basic views to an empty layout and resolved a couple of "coding practice" warnings, when I try to run the app on a USB connected tablet, I get a build failed message.
(I haven't got as far as any Kotlin coding yet.)
I'm completely out of my depth at this stage and can't find a solution that isn't beyond my level of understanding.
The errors are ...
Caused by: java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
Caused by: java.lang.ClassNotFoundException: kotlin.reflect.full.KClasses
If there's any other information worth sharing, I'm afraid I don't know what it is at the moment.
ANy suggestions on what I need to do to or investigate to resolve the build fail?
First build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.10"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
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()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Second build.gradle file:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.test04"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.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 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Try these steps.
Update your Kotlin version from "1.5.10" to the latest "1.5.31" in your first build.gradle file. Also update the Kotlin plugin: File -> Settings -> Languages and Frameworks -> Kotlin and if there's a new version there will be an Install button to click. Then restart Android Studio and run your project to see if it will work.
If that doesn't work, you can manually add the missing reflection library to your project. I don't see in your dependencies anything that uses reflection, but maybe I'm missing something. So, add this line into the dependencies section of your second build.gradle file:
implementation "org.jetbrains.kotlin:kotlin-reflect"
Then click the "Sync Project with Gradle Files" button near the right end of the toolbar (elephant with blue arrow icon), and try running your project again.
The Android Build Tools you're using is also out of date. I'm not sure it could be related, but you can update that as well in the first build.gradle file. Change the 4.2.2 to 7.0.3 and click the Gradle sync button again. Android Studio might complain that you need to update your Gradle version, so click yes if it offers to update it for you.

appcompat-v7:28.0.0-beta01 Broke after update

I am beginner in Android studio and installed it yesterday. Then I created a empty project that worked just fine. Today I had to update and now I am fighting with that error message:
As you can see I already included the Examples. Any ideas how I can fix that?
Here the full app.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "at.sumser.fateandlove"
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"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
implementation 'com.android.support:support-media-compat:26.1.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0-beta01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
implementation'com.google.android.gms:play-services-location:15.0.1'
}
Funny, that it tells me to add 'com.android.support:support-media-compat:26.1.0' when the SDK is 28? Any ideas?
UPDATE
Here is also the build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
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
}
Now the 'com.android.support:support-media-compat:26.1.0' does also tell me about a problem:
Question: Does Google not test their releases? Or is the autoresolver in Android Studio just broken? I lost now nearly 3 hours to find a fix for this issue...
I just had the same issue when updating to AppCompat version 28.
First I recommend to use the latest version which is 28.0.0-rc01 instead of 28.0.0-beta01.
If you then still get the warning that all libraries must use the exact same version specification, you can force to use the latest version for the corresponding library.
You can do so by adding a resolution strategy to your apps build.gradle file within android { } like this:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:28.0.0-rc01'
force 'com.android.support:support-media-compat:28.0.0-rc01'
force 'com.android.support:customtabs:28.0.0-rc01'
}
}

Error: more than one library with package name 'android.support.graphics.drawable'

I am trying to learn android studio. In this computer ( its not mine) android studio version is 2.2.3
When i created a new project while gradle build an error occurs.
Error:Execution failed for task ':app:processDebugResources'.
Error: more than one library with package name 'android.support.graphics.drawable'
I have been searching for this error for one day. I haven't found the same topic anywhere so i have to open this thread.Thanks for all answers from now.
this is build.gradle(project:myapplication2)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and this is build.gradle(module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.0"
defaultConfig {
applicationId "com.example.alicetin.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'])
compile 'com.android.support:appcompat-v7:28.+'
testCompile 'junit:junit:4.12'
}
Try
implementation 'com.android.support:appcompat-v7:27.1.1'
instead of
compile 'com.android.support:appcompat-v7:28.+'
appcompat-v7 version 28 is still alpha
Try
classpath 'com.android.tools.build:gradle:3.2.1'
instead of
classpath 'com.android.tools.build:gradle:2.2.3'
I faced the same issue and It worked for me.
Use:
compile 'com.android.support:appcompat-v7:27.+'
Instead of:
compile 'com.android.support:appcompat-v7:28.+'
I faced the exact same problem although my build.gradle(app) file has already been updated with the latest production version of SDK, tools and libraries.
The only thing left to check is the gradle version and in fact there was a warning saying that a newer gradle version is available. Please refer to image below.
more than one library with 'android.support.graphics.drawable'
Once I uprev the gradle version, the error got resolved.
So please upgrade your gradle version from 2.2.3 to a newer version.
"com.android.support:appcompat-v7" depends on "support-vector-drawable"
and
"com.android.support:design" depends on "animated-vector-drawable"
Add this to your build.gradle:
configurations.all {
exclude module: 'animated-vector-drawable'
}
Sush as:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// ...
configurations.all {
exclude module: 'animated-vector-drawable'
}
}

Google services ; com.google.gms:google-services:2.1.2 ; failed to resolve services-measurement

Just trying to update to the latest google play services 9.4.0. If I leave the classpath in the application level gradle to 2.1.2 which seems to be the latest release as of June 03, link, I get the error failed to resolve :
Error:Failed to resolve: com.google.android.gms:play-services-measurement:9.4.0
Install Repository and sync project
I have already my packages updated in SDK manager.
If I leave the classpath as 3.0.0 which was the release of May things seem to be ok. Any idea as to why I get such error with the 2.1.2 version classpath? see below for my gradle files. Android Studio version : 2.1.3. Appreciate any help.
build.gradle Project Level:
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.google.gms:google-services:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenLocal()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle app Level:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.example.main.projectone"
minSdkVersion 18
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
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.facebook.android:facebook-android-sdk:4.7.0') {
exclude module: 'bolts-android'
}
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.parse:parse-android:1.13.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0#aar'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.firebase:geofire-android:2.0.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
compile 'com.google.firebase:firebase-storage:9.4.0'
}
apply plugin: 'com.google.gms.google-services'
Since you are using the version 9.4.0 you have to use the google play service plugin v 3.0.0:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
}
Check the official documentation for the setup.

Unable to resolve Robotium Dependency Android Studio

I am trying to use Robotium for writing test cases in Android Studio and I am having a hard time configuring things.
Following is my build.gradle inside the app.
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.1'
androidTestCompile 'junit:junit:4.11'
}
When I clean the project, I get the following error:
Error:A problem occurred configuring project ':NativeSDK'.
Could not resolve all dependencies for configuration ':NativeSDK:_debugTestCompile'.
Could not find com.jayway.android.robotium:robotium-solo:5.1.
Required by:
InAppSDK:NativeSDK:unspecified
Could not find junit:junit:4.11.
Required by:
InAppSDK:NativeSDK:unspecified
Any help on how to resolve this?
I hope that in your top level build.gradle you have the repositories{mavenCentral()} or repositories{jcenter()} in your buildscript{}
When you provide the reference to an artifact in mavenCentral() or jCenter() you need to sync the project after disabling the offline work at least once under studio>preference>gradle>offline work.
Having this will solve the issue. Its just the local cache of the studio has not been updated as per my understanding. You can check the available library version in mavenCentral() or jcenter() in your case its 5.1 for robotium. (better to use 5.2.1 which is the newest as of today)
make sure that you don't have the robotium jar in your libs folder as you are compiling libs file tree. If you have the jar file when compiling it will throw a UNEXPECTED_TOP_LEVEL exception.

Resources