I have written a small code, but whenever I try to build the apk, I get the following error:
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.multidex.ClassReferenceListBuilder with arguments {C:\Users\xxxx\Desktop\yyyyy\app\build\intermediates\multi-dex\debug\componentClasses.jar C:\Users\xxxx\Desktop\yyyyy\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}
Where xxxx is my username, and yyyyy is project name.
I have tried all possible solutions that I found on Stack Overflow, but I realized that all of them were asked about older versions.
I have the latest version of Android Studio. I am using latest version of Android SDK, the build tools, gradle, JDK 8.0 , and JRE 7. I also tried JRE 8.
build.gradle(module app) :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "xxxx.yyyyy"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "Unreleased Demo Version"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
}
In you build.gradle/app
defaultConfig {
....
//Add this line
multiDexEnabled true
}
dependencies {
....
//Add this line
compile 'com.android.support:multidex:1.0.0'
}
This happens as the Android platform has continued to grow, so has the size of Android apps. When your app and the libraries it references reach a certain size, you encounter build errors that indicate your app has reached a limit of the Android app build architecture
Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here: Source
android {
defaultConfig {
multiDexEnabled true
}
}
Try this in Module:App gradle folder.
multiDexEnabled true
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
I found there is no need to install JDK and JRE (ref:android studio 2.3.2 latest download page under system requirements)
And there is a folder named "jre" in programfiles/android-studio.
So I thought I shall uninstall JDK and JRE (as the problem related to java)
After this I reinstalled android studio.
And now it works fine.
(I haven't done research in deep although it helped me)
You have not shared any of your codes and dependencies you working with ,so it is difficult to guess exact problem.
but from error you posted ,i think your program cross the limit of 64K Methods.
Apk files conatins bytecode files in the form of DEX, and it has a limit of 65,536 methods in a single DEX file.
So if your App has more then 64k methods ,you should go for multiple Dex files.
Enabling mutiple Dex ,means app build process will generate more than one DEX file
defaultConfig {
....
multiDexEnabled true
}
dependencies {
....
compile 'com.android.support:multidex:1.0.0'
}
This happen when your have cross 65,536 method reference limit.
Step 1
You can add the following to your app's build.gradle file
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Step 2A
After that you have to extend the Application class in the following way
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Or you can do as below:
Step 2B
public class MyApplication extends MultiDexApplication { ... }
STEP 3
Finally update your manifest file like below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
Related
While generating signed apk from Android Studio getting an error. A few days later all works good, while from last 2 days I am facing problem to generate signed apk.
Error is:
FAILURE: Build failed with an exception. What went wrong: A problem
was found with the configuration of task ':app:packageRelease'. File
'/media/user86/data/MySIPonline/app/build/intermediates/res/resources-release-stripped.ap_'
specified for property 'resourceFile' does not exist.
I've checked that folder and release-stripped.ap file is present in it. I am not able to figure out the error.
Here is build.gradle (app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.xxxxxxxx"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'de.petendi:ethereum-android-lib:0.2.1'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:design:26.0.0-alpha1'
testCompile 'org.ethereum:ethereumj-core:1.2.0-RELEASE'
testCompile 'commons-io:commons-io:2.4'
testCompile 'junit:junit:4.12'
}
configurations.all {
resolutionStrategy {
force 'com.fasterxml.jackson.core:jackson-databind:2.7.1-1'
force 'com.fasterxml.jackson.core:jackson-annotations:2.7.0'
force 'com.fasterxml.jackson.core:jackson-core:2.7.1'
}
}
Here is link for pro-guard file - https://gist.github.com/Sanwal13/b667326812b87702c86fa02870b28240
Please help and thank you very much for your time and assistance in this matter.
I'm working on an android app using android studio for school and I'm trying to use Jersey client to connect the app with my web services. I'm getting the following error when I attempt to add the jars required for Jersey client and compile the project.
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
From searching around for a solution to this problem it seems to me it is occurring because I am exceeding a 65k limit on methods by adding the jars. I've also seen that this can be fixed by using multidex support which I have tried to implement but the error remains when I compile the gradle.
Here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.williamj.hertz"
minSdkVersion 15
targetSdkVersion 23
multiDexEnabled true
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions{
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
exclude 'META-INF/LISCENSE.txt'
exclude 'META-INF/LISCENSE'
exclude 'META-INF/liscense.txt'
}
dexOptions{
incremental true
preDexLibraries = false
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.parse:parse-android:1.10.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.github.flavienlaurent.datetimepicker:library:0.0.2'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:multidex:1.0.1'
}
And here is a portion of my AndroidManifest where I have added multidex support
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:name="android.support.multidex.MultiDexApplication">
I'm assuming that I'm just not implementing multidex support correctly. Any help in fixing this error would be greatly appreciated, thank you.
Have your Application override attachBaseContext:
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
link: http://developer.android.com/tools/building/multidex.html
2nd methode:
I also noticed that you are including all Google play services:
compile 'com.google.android.gms:play-services:8.4.0'
You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them. For information on how to do this, see: https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':Q-municate_core')
compile project(':cropper')
compile project(':stickyListHeaders')
compile "com.nostra13.universalimageloader:universal-image-loader:${rootProject.universalImageLoaderVersion}"
compile "com.google.android.gms:play-services:7.5.0"
compile('de.keyboardsurfer.android.widget:crouton:1.8.4#aar') {
exclude group: 'com.google.android', module: 'support-v4'
}
compile "com.nineoldandroids:library:${rootProject.nineoldandroidsVersion}"
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
compile 'com.crashlytics.android:crashlytics:1.+'
}
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode rootProject.versionCode
versionName rootProject.versionName
}
buildTypes {
release {
debuggable rootProject.prodDebug
signingConfig signingConfigs.debug
minifyEnabled false
proguardFile 'proguard.cfg'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
lintOptions {
abortOnError false
}
}
This is my build.gradle file
I couldn't understand where I go wrong please help in this way.
when I compile this file I got the error
org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_72\bin\java.exe'' finished with non-zero exit value 2
I can't see your buildToolsVersion in the gradle. Have the latest build told version and also remove the unnecessary dependencies.
Follow this.
You added dependency in wrong gradle file. see here two types of gradle
add dependency in build.gradle(Module : app)
and for understanding its feature use this link
build.gradle(Module:app) have to be like this-->
and project gradle file have to be like this --->
if any dependency you want to add then add in build.gradle(app)
This error is all about you have many huge libraries. So your method count is higher than 65k. It makes your dex file is large. This is why you are taking a error while executing "dexDebug".
Solution is quite simple. You should implement Multidex.
It's because one of the libraries that you are adding contains a compile error.
try to remove each time one library and compile, you can know than which of them is causing the error.
I think you should start with nineoldandroids library.
I am still using Android Studio 0.8.9 on my Macbook Air. On my iMac i installed Android Studio 1.0.
As 1.0 only supports 'com.android.tools.build:gradle:1.0.0' i had to change my build.gradles
as mentioned here. Gradle DSL method not found: 'runProguard'
0.8.9 uses 'com.android.tools.build:gradle:0.12.2'
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example...."
minSdkVersion 19
targetSdkVersion 20
versionCode 1
versionName "0.87"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
dexOptions {
preDexLibraries = false
} }
repositories {
mavenCentral()
flatDir {
dirs 'libs'
} }
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.android.gms:play-services-wearable:+'
compile 'com.spotify.sdk:spotifysdk:1.0.0-beta6#aar'
compile('se.michaelthelin.spotify:spotify-web-api-java:1.4.20')
}
With the 0.8.9 beta on my MacBook Air my App builds fine. On my iMac i get this error.
org.apache.commons.collections.ArrayStack has already been added to output. Please remove duplicate copies.
UPDATE
The problems seems to be that commons-collections is added to the external libraries and commons-beanutils which also includes a commons-collections.
compile('se.michaelthelin.spotify:spotify-web-api-java:1.4.20') {
exclude group: "commons-beanutils", module: "commons-beanutils"
}
if i exclude the commons-beanutils the build process is fine, but the app crashes, as it needs the commons-beanutils. same if i exclude the commons-collections.
furthermore i tried to manually remove the folder common-collections from the commons-beanutils jar, but this also does not work..
finally it works.
this one does not include commons-collections, so everything works fine.
compile 'commons-beanutils:commons-beanutils:20030211.134440'
don't understand why this was not necessary in beta 0.8.9
compile('se.michaelthelin.spotify:spotify-web-api-java:1.4.20') {
exclude group: "commons-beanutils", module: "commons-beanutils"
}
compile 'commons-beanutils:commons-beanutils:20030211.134440'
Try:
project > clean
project > rebuild
and run again
I'm trying to import https://github.com/Kickflip/kickflip-android-sdk using gradle into my android build and I'm getting :
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/codec/binary/Base64;
Commons.codec is a dependency of my project, but not directly of the kick-flip project, I think its coming from one of the jars included there. I can see the .class files if I open Kickflip's classes.jar.
How can I exclude Base64.class from being imported from kickflip into the final build? I've looked at using ziptree to exclude things but haven't been able to get anything to work.
Thanks
My build.gradle is:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/ASL2.0'
}
android.applicationVariants.all{ variant ->
// This is an annoying hack to get around the fact that the Gradle plugin does not support
// having libraries with different minSdkVersions. Play Services has a min version of 9 (Gingerbread)
// but Android Maps Utils supports 8 (Froyo) still
variant.processManifest.doFirst {
File manifestFile = file("${buildDir}/exploded-aar/io.kickflip/sdk/0.9.9/AndroidManifest.xml")
if (manifestFile.exists()) {
println("Replacing minSdkVersion in Android Maps Utils")
String content = manifestFile.getText('UTF-8')
content = content.replaceAll(/minSdkVersion="18"/, 'minSdkVersion=\"10\"')
manifestFile.write(content, 'UTF-8')
println(content)
}
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'io.kickflip:sdk:0.9.9'
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':libs:typeface-textview:library')
compile project(':libs:gpuimage')
compile 'com.google.android.gms:play-services:4.3.23'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.koushikdutta.urlimageviewhelper:urlimageviewhelper:1.0.4'
compile ('fr.avianey:facebook-android-api:3.14.0') {
exclude module: 'support-v4'
}
compile 'com.github.japgolly.android:svg-android:2.0.1'
compile 'org.scribe:scribe:1.3.5'
compile 'commons-codec:commons-codec:1.8'
}
Probably the problem is Base64 class included twice. It is in the 'google-http-client' (view it). Try to exclude this class. If you're lucky, being an Util class, it isn't used in the code.
Try this in your build.gradle:
package com.google.api.client.util;
sourceSets {
main {
java {
exclude 'com.google.api.client.util.Base64.java'
exclude 'org.apache.commons.codec.binary.Base64.java'
}
}
}
NOTE: I don't tried it yet, but sounds as a possibility