Convert project from Android Studio version 2 to 3- problem with configuration - android

I have problem with configuration of android project. I upgraded Android Studio [AS] from v2 to v3 and got many problems. I changed gradle as is in documentation:
gradle-wrapper, gradle plugin version, repositories google or jcenter instead of maven. Please look at configuration:
I have project called mytwayapp which have build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
//{ url "http://jcenter.bintray.com/" }
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
dependencies {
implementation project(':app')
}
Next I have module called app with build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '27.0.3'
// buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.mytway.activity.registerformactivity"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false;
javaMaxHeapSize "2g"
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/res/assets/fonts'] } }
testOptions {
unitTests.returnDefaultValues = true
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.gms:play-services:8.4.0'
implementation 'com.android.support:appcompat-v7:23.1.1'
implementation 'com.android.support:support-v4:23.1.1'
implementation 'com.android.support:support-v13:23.1.1'
implementation 'joda-time:joda-time:2.9.4'
implementation files('../libs/MPAndroidChart-v3.0.1.jar')
//to remove when Dex is over memory
testImplementation group: 'org.powermock', name: 'powermock-api-easymock', version: '1.6.6'
testImplementation 'org.powermock:powermock-mockito-release-full:1.5.4'
testImplementation 'org.powermock:powermock-api-mockito:1.6.6'
testImplementation 'org.powermock:powermock-module-junit4:1.5.1'
testImplementation 'org.mockito:mockito-all:1.9.5'
testImplementation 'org.powermock:powermock-mockito-release-full:1.6.1'
testImplementation 'org.easymock:easymock:3.1'
// testCompile files('build/lib/powermock-easymock-1.6.6-full.jar')
testImplementation 'junit:junit:4.12'
}
Next is gradle-wrapper:
#Thu Mar 16 20:14:22 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Problem:
I cannot sync with gradle,If I try then error:
Could not initialize class com.android.tools.idea.gradle.eclipse.GradleImport
When I try install from cmd, then:
./gradlew install -x test
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\android\BitBucket\mytwayapp\build.gradle' line: 22
* What went wrong:
A problem occurred evaluating root project 'mytwayapp'.
> Could not find method implementation() for arguments [project ':app'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
It means that problem is with main build.gradle with dependencies to ":app" but it looks good.
I tried refreshed, rebuild, invalidate, restarted and still have a problem.
Project structure looks strange here is a screen:
ANSWER:
Tips from below are not worked, I downgrade Android Studio from 3.4 to 3.1 and after some cosmetics change it compile. Thanks for your time.

Try to update to latest versions:
dependencies {
classpath 'com.android.tools.build:gradle:x.x.x'
}
And buildToolsVersion in build.gradle

Try change de compileSDkVersion and targetSdkVersion with the same number prefix of buildToolsVersion in app gradle file, like this:
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
// buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.mytway.activity.registerformactivity"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
}

Related

Failed to calculate the value of task ':app:mergeLibDexDebug' property 'numberOfBuckets'. Expected minSdkVersion >= 21 but found 1

Have a good day everyone. I am starting my studies in Kotlin using Android Studio in its version 4.2.2. I have created a project from 0 using the IDE itself and I get the error:
Execution failed for task ':app:mergeLibDexDebug'
Failed to calculate the value of task ':app:mergeLibDexDebug' property
'numberOfBuckets'.
Expected minSdkVersion >= 21 but found 1
I was looking in other publications that spoke of compilation problems mainly due to incompatibilities in the dependencies included in the project, but none spoke exactly about the error that I am presenting...
The gradle module has the default code when creating the application which is the following:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.example.nueva"
minSdkVersion 28
targetSdkVersion 30
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.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
The gradle project also has the default configuration that it brings when the application is created:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.20"
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
}
I don't have any additional implementation either in MainActivity.kt or another project file. If anyone has been through this error and fixed it please I would really appreciate if you would share with me how to eliminate this error. Maybe the solution is simple, but as I said before I am new to the world of Kotlin and I would like very much in the future to be able to be involved in the world of developing applications for smartphones. Without further ado, thank you very much in advance to anyone who can help
Can you make sure test on a Device >= API Level 21 ? Also check from Settings for New Projects to be selected Android 11.0 (R) or Android 9.0 Pie (check also these versions are installed in sdk manager)

Problema with aapt.exe with build tools 23.0.2: Exception in thread "png-cruncher_3" java.lang.RuntimeException

I created a simple project using Android Studio, but the build process is not finishing...
My project configuration:
APP build.gradle
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
buildscript {
repositories {
mavenCentral()
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:1.5.0'
// replace with the current version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
//Gradle Daemon Support for Faster Compilation
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.12.1230'
}
}
repositories {
mavenCentral()
mavenLocal()
}
def AAVersion = '3.3.2'
dependencies {
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
}
apt {
arguments {
androidManifestFile variant.outputs[0]?.processResources?.manifestFile
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "br.com.myapp"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
mavenLocal()
maven {
url "https://mint.splunk.com/gradle/"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
// rastreamento de crashes do sistema
compile 'com.splunk.mint:mint:4.4.0'
//Retrofit
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
// Trabalhar com datas
compile 'joda-time:joda-time:2.3'
//Socket.IO-client
compile 'io.socket:socket.io-client:0.6.2'
//MATERIAL EDITTEXT
compile 'com.rengwuxian.materialedittext:library:2.1.4'
}
gradle-wrapper.properties
#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Configuration on AS
I know I'm not using the recommended version, but it doesn't make difference, because Android Studio is using the same version of the file gradle-wrapper
THE PROBLEM
It does not finish!
Is there something what I can do in this case?
EDIT:
I noticed this:
Exception in thread "png-cruncher_3" java.lang.RuntimeException: Timed out while waiting for slave aapt process, make sure the aapt execute at C:\Android\sdk\build-tools\23.0.2\aapt.exe can run successfully (some anti-virus may block it) or try setting environment variable SLAVE_AAPT_TIMEOUT to a value bigger than 5 seconds
at com.android.builder.png.AaptProcess.waitForReady(AaptProcess.java:108)
at com.android.builder.png.QueuedCruncher$1.creation(QueuedCruncher.java:110)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:203)
at java.lang.Thread.run(Thread.java:745)
Many processes in background of aapt:
there are 2 possible solutions in windows :
the first check your local variables must have SLAVE_AAPT_TIMEOUT = 30
and JAVA_HOME = C:\Program Files\Java\ jdk1.8.0_65
if this does not work , then you must have the sdk damaged , remove it . the installation path , and C:user\username\ delete .android , .gradle , and any folder that has to do with Android Studio avoiding any possible cache that could produce the error , then re-download the sdk , that should work

Task 'install' is ambiguous in root project 'TestApp'. Candidates are: 'installDebug', 'installDebugAndroidTest'

I am working on one library project in android. I want to upload my library to the JCenter. I have created bintray account etc & followed all steps which are mentioned here http://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
I did below changes in my application module & library module.
Application Module build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.app.testapp"
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile project(':testlib')
}
Library Module build.gradle
apply plugin: 'com.android.library'
ext {
bintrayRepo = 'maven'
bintrayName = 'test-sdk'
publishedGroupId = 'in.test.sdk'
libraryName = 'testlib'
artifact = 'test-sdk'
libraryDescription = 'A wrapper for Facebook Native Like Button (LikeView) on Android'
siteUrl = 'https://github.com/xyz/testsdk'
gitUrl = 'https://github.com/xyz/testsdk.git'
libraryVersion = '1.0.0'
developerId = 'xyz'
developerName = 'xyz'
developerEmail = 'xyz#xyz.xyz'
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
version = "1.0.0"
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// proguardFiles 'proguard-project.txt'
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.0'
compile files('libs/gson-2.3.1.jar')
compile files('libs/android-query-full.0.26.8.jar')
compile files('libs/httpmime-4.1.1.jar')
compile files('libs/jackson-annotations-2.5.0.jar')
compile files('libs/javax.annotation.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/okhttp-2.3.0.jar')
compile files('libs/okio-1.3.0.jar')
compile files('libs/retrofit-1.9.0.jar')
}
Project root build.gradle
// 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:1.1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
When I am doing this gradlew install then I am getting this error
FAILURE: Build failed with an exception.
* What went wrong:
Task 'install' is ambiguous in root project 'TestApp'. Candidates are: 'installDebug', 'installDebugAndroidTest'.
* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 11.685 secs
I spent three days on same but could not get proper solution of it. Please suggest how to resolve it.
Perhaps you forgot to add these lines to the end of your Library Module build.gradle:
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
You are telling gradle to do the 'install' task but it is telling you that there is no 'install' task and gives suggestions of close task matches like 'installDebug'.
Basically your plugins do not include an install task. If you want to see all the tasks that are available to you run the command below
gradlew tasks --all

Debug has an indirect dependency on Android API level X, but minSdkVersion for variant 'debug' is API level Y

I have a Android project created with Android Studio. I have added some third party dependencies to the project, but when I try to compile in Android Studio I hit the following error:
Error:Execution failed for task ':app:prepareDebugDependencies'.
> ERROR: Debug has an indirect dependency on Android API level 14, \
but minSdkVersion for variant 'debug' is API level 8
Compiling on the command line with ./gradlew works fine.
What does this error mean?
How do I fix it?
Many thanks.
UPDATE:
My top level build.gradle file:
[snowch#laptop MyApplication]$ cat build.gradle
// 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:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenLocal()
mavenCentral()
maven { url "http://maven.restlet.org" }
}
}
The application module's build.gradle:
[snowch#laptop MyApplication]$ cat app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.snowch.myapplication"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
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:21.0.3'
compile 'net.christophersnow:sync-android-p2p:0.0.1-SNAPSHOT'
compile("org.restlet.jse:org.restlet:2.1-M7") {
exclude group: 'org.osgi', module: 'org.osgi.core'
}
compile("org.restlet.jse:org.restlet.ext.simple:2.1-M7")
}
Setting the minSdkVersion to 14 in the app\build.gradle file fixed the issue for me.
Thanks to murtaza-hussain and gabriele-mariotti for the inspiration.

Unable to build with Support Library on Travis CI/Android SDK v20

I hope this shouldn't be too challenging, but:
Currently I'm trying to build a project in Android/Travis CI, which you can find over here. I'm trying to use the Android L developer preview, and build with Travis-CI. I was hoping that using the Gradle SDK Manager plugin would allow me to do this. Unfortunately, it doesn't. I don't know if my build.gradle file is set up improperly, or what, but I was hoping someone might be able to point me in the right direction.
Build error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_testConfigDebugCompile'.
> Could not find any version that matches com.android.support:appcompat-v7:20.+.
Required by:
MinimalBible:app:unspecified
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.10.+'
}
}
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId 'org.bspeice.minimalbible'
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.squareup.dagger:dagger:1.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'
compile 'com.android.support:appcompat-v7:20.+'
}
Let me know if any further information is required.
try something like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//force complie with 20.0.0
compile ('com.android.support:appcompat-v7:20.0.0'){force = true}
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.1'
}

Categories

Resources