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
Related
I'm trying to integrate Millennial Media SDK 6.4 in my Android app, but it shows an error message below when I run the app on my phone.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/gcm/PendingCallback$1.class
At first, I run the sample code with latest SDK downloaded directly from Millennial Media site, and it worked perfectly on my device. Then I migrated the inline ad code into my app following the official integration guide and there were no any problems when compiling or cleaning the project until I attempted running it in my phone. Please see my build.gradle file below.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId '<My Application ID>'
minSdkVersion 16
targetSdkVersion 25
versionName '1.0'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
versionCode 5
versionNameSuffix '5'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding.enabled = true;
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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:design:25.3.1'
compile 'com.android.support:preference-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.firebase:firebase-jobdispatcher:0.6.0'
compile 'com.android.support:support-v4:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
compile project(':android-ad-sdk')
compile 'com.google.android.gms:play-services:10.2.4'
}
I have tried cleaning gradlew, updating the gradle version and restarting the project, but nothing works. I have also contacted Millennial Media support team a day ago, though no response has been heard yet.
Have anyone seen this problem or known how to fix. Please give me any advices that I will appreciate. Or do you use other ad network providers that could be better than Millennial Media?
Cheers.
Update 1:
I've tried commenting compile "com.google.android.gms:play-services:10.2.4". Although it built the app, it showed a fatal exception below when I started the activity with the ad.
E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
java.lang.NoClassDefFoundError: com.google.android.gms.common.GoogleApiAvailability
at com.millennialmedia.internal.utils.EnvironmentUtils.getAdInfo(EnvironmentUtils.java:356)
at com.millennialmedia.internal.utils.EnvironmentUtils$1.run(EnvironmentUtils.java:132)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
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>
I have just installed new Android Studio and tried to create a new project. But I get this strange error. I am using 32 bit Linux system.
Error:Execution failed for task ':app:mergeDebugResources'.
Error: java.util.concurrent.ExecutionException: java.lang.RuntimeException: AAPT process not ready to receive commands
Information:BUILD FAILED
Error:java.util.concurrent.ExecutionException: java.lang.RuntimeException: AAPT process not ready to receive commands
Information:Total time: 14.838 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console
I don't understand why I am getting this error.
Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.sandesh.testing"
minSdkVersion 15
targetSdkVersion 25
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'])
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.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
Gradle (project)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.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
}
In your case problem is newest Android Studio does not run on 32bit only system. On download page you can check the requirement also:
64-bit distribution capable of running 32-bit applications
The newest version does not support 32bit. I think you should try with one solution but I dont know how long it will work :
Step1.Go to terminal
Step2.type gedit .profile
Step3.paste the below line at end of the page
Step4.export ANDROID_EMULATOR_FORCE_32BIT=true
Step5.type source .profile in terminal or restart system
Please remember that may be in future Android Stdio stop supporting this too so its better you should move to bit64 or downgrade your version of android studio.
I am trying to run my application with instant run turned off but I get this error:
Error:Execution failed for task
':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
android/support/v4/view/KeyEventCompatEclair.class
Here is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.jua.app"
minSdkVersion 16
targetSdkVersion 21
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.android.support:appcompat-v7:23.4.0'
compile project(path: ':app_Data')
compile files('libs/android-support-v4.jar')
}
I tried the solution from this thread:
compile files('libs/android-support-v4.jar'){
exclude module: "support-v4"
}
And now I am receiving this error when I try to Sync now gradle.build:
Error:(29, 0) Could not find method exclude() for arguments
[{module=support-v4}] on file collection of type
org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection.
Open File
I am a little lost right now, If anyone has any idea how to solve this I would appreciate it.
EDIT
I removed
compile files('libs/android-support-v4.jar')
completly and I still get the first error.
This is a syntax issue. The closure in which you are calling exclude is being interpreted as an argument to the files() method, which is incorrect. Should look like this
compile (files('libs/android-support-v4.jar')){
exclude module: "support-v4"
}
For anyone having the same problem, I deleted android-support-v4.jar from folder and now it works. For some reason, if you remove it from inside the gradle.build file it continues to create problems.
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.