If i write in my gradle file this code
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
}
all work cool. but if i change
compile 'com.android.support:appcompat-v7:22.1.0'
my app crash. Android studio recomended me change version to 22.1.0 but if i chage version - crash.
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\zen_75\AppData\Local\Android\sdk\build-tools\22.0.1\dx.bat --dex --no-optimize --output C:\projects\android-customer\app\build\intermediates\dex\debug --input-list=C:\projects\android-customer\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
how do I fix it or leave it?
EDIT:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.0'
}
i change file - not work!!!
You have Over 65K Methods in you project, seems like Google has add a lot of now methods to the appcomapt-v21.1 libs.
Anyway, For now you have those options:
1. Use Multidex, Follow the instructions below, more info here
2. Use the ProGuard
3. Cut down the number of methods you have in your project
You have to keep in mind:
Multidex may not work on devices running Android v3.x-, check all limitations here
ProGuard is not guaranteed to solve the problem
Re-write you code to cut down the number of methods is not easy.
Add multidex support:
build.gradle
android {
...
...
defaultConfig {
...
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
...
...
compile 'com.android.support:multidex:+'
}
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="x.xxx.xx">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
PS: You can count the number of methods you have in your project using dex-method-counts, it will give you a clear idea about your situation.
A possible solution is to start using ProGuard's minify capability. Please note that it breaks Dagger dependency injection over version 1.0.1.
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Test your application extensibly, as this removes unused methods, and does many other things.
http://developer.android.com/tools/help/proguard.html
Related
How do you debug JUnit test case in Android studio? I placed a breakpoint and used "Debug Test case" but it just runs the code and the breakpoint is ignored.
Update:
This is content of my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.****.mancala"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
Depending on the Run/Debug Configuration used, the same code with the same breakpoint will stop or not.
For a configuration with Test kind: All in package, the execution
will not stop at breakpoint
For a configuration with Test kind: Class or Test kind: Method, the execution will stop at breakpoint
For a configuration with Test kind: All in directory with Directory: [myProjectPath]/app/src/test, the execution will stop at breakpoint
Make sure that in your build.gradle file (one with all your dependencies) that you have debuggable true within the debug build type.
Also just for good measure make sure its a valid breakpoint (not an empty line etc.)
when I pressed run button I checked apk floder where app-debug-unaligned.apk generated but app-debug.apk not refreshed. I don't know what I did that this happened. check the date in picture
EDIT: maybe people think I am lying but it's not true. maybe problem is in build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "ir.parsdroid.instagrameducation"
minSdkVersion 8
targetSdkVersion 23
versionCode 11
versionName "1.5.3"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFile 'proguard-android-optimize.txt'
zipAlignEnabled false
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile files('src/main/libs/adad-2.9.jar')
}
In android studio, APK gets generated when we rebuild an application or run an application.
To get debug apk :
Rebuild your project or run your project
check your_app_location\app\build\outputs\apk
Edited :
Here in your gradle file you have used 'zipAlignEnabled' :
debug {
minifyEnabled true
proguardFile 'proguard-android-optimize.txt'
zipAlignEnabled false
}
Problem is because of it. So please check how to use 'zipAlignEnabled' and try again.!!
Hope it will help.
Agree with Mamata Gelanee. You can simply remove app-debug.apk file from folder and clean the project and release new build again then check.
I am using google play services version 7.5.0 and getting below mentioned error while running a project.
My project contains 2 modules.
Here are the build.gradle file of each modules.
Module 1:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
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:support-v4:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
}
Module 2:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
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 project(':module1')
}
And here is build.gradle file of app
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "com.vserv.offerwall"
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
dexOptions {
jumboMode true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':module2')
}
repositories {
flatDir {
dirs 'libs'
}
}
When I am building the app, it get build successfully. But when I am trying to run the app, I am getting below mentioned error.
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_45\bin\java.exe'' finished with non-zero exit value 2
I have done some Google and found below mentioned link.
Unable to execute dex: method ID not in [0, 0xffff]: 65536
I have tried this and edited the app gradle file by adding multiDexEnabled true into defaultConfig and compile 'com.android.support:multidex:1.0.0' in dependencies.
After that the above mentioned error is resolved and then I got another error while running the app.
:app:shrinkDebugMultiDexComponents FAILED
Error:Execution failed for task ':app:shrinkDebugMultiDexComponents'.
java.io.IOException: Can't read [D:\StudioWorkspace\SampleSDKDemoProject\app\build\intermediates\multi-dex\debug\allclasses.jar] (Can't process class [org/fmod/FMODAudioDevice.class] (256))
Kindly help me to solve this.
Thanks in advance.
Instead of importing ALL modules from google services
compile 'com.google.android.gms:play-services:7.5.0'
Import only the modules you need. Check this page.
Note: If the number of method references in your app exceeds the 65K
limit, your app may fail to compile. 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.
I have two libraries on my proyect.
https://github.com/rengwuxian/MaterialEditText
https://github.com/navasmdc/MaterialDesignLibrary
It compiles, but when I run the program it reports an error.
UNEXPECTED TOP-LEVEL EXCEPTION:
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Alvaro\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output D:\ALVARO\AndroidStudioProjects\Proyecto\app\build\intermediates\dex\debug --input-list=D:\Alva\AndroidStudioProjects\Proyecto\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/nineoldandroids/animation/Animator$AnimatorListener;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
I KNOW THE PROBLEM, BUT I CAN'T SOLVE
Problem
Multiple dependencies are trying to import nineoldandroids exactly "nineoldandroids"
app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.alva.proyecto"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
//seconds library
compile project(':materialDesign')
//first library
compile project(':EditText')
}
first library build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:support-annotations:21.0.3'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.android.support:appcompat-v7:21.0.3'
}
seconds library build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 8
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.+'
compile files('libs/nineoldandroids-2.4.0.jar')
}
I have tried:
1. Put on "app" build.gradle:
compile project(':EditText') {
exclude group: 'com.nineoldandroids', module: 'library:2.4.0'
}
NOT WORKS, IT'S REPORTS AN ERROR
Error:(31, 0) Gradle DSL method not found: 'exclude()'
Possible causes:<ul><li>The project 'Proyecto' may be using a version of Gradle that does not contain the method.
Gradle settings</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
2. Remove "nineoldandroids" from seconds library, NOT WORKS
Any suggestions?
I don't know how to import using their respective artifacts
It is in the documentation for each library.
The MaterialEditText "Download" section cites:
compile 'com.rengwuxian.materialedittext:library:1.8.2'
The "How to Use" section of MaterialDesignLibrary cites:
repositories {
jcenter()
}
dependencies {
compile 'com.github.navasmdc:MaterialDesign:1.+#aar'
}
Then, Gradle will (hopefully) be able to detect that both of these dependencies themselves depend upon nineoldandroids and resolve the conflict. I say "hopefully" because whichever library the "seconds library build.gradle" comes from uses a local copy of nineoldandroids, which is not a good idea. Neither GitHub repo seems to have that particular build.gradle file, though, so you may be OK.
I'm trying to use this new feature available in the version 0.10.0 of the Gradle Plugin for Android. But I keep getting this error message:
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':xxxxxx:processDebugManifest'.
Manifest merger failed : uses-sdk:minSdkVersion 1 cannot be smaller than version 7 declared in library
com.android.support:appcompat-v7:19.1.0
Here's my build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
useOldManifestMerger false
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
buildTypes {
release {
runProguard true
proguardFile 'proguard-zap.cfg'
signingConfig signingConfigs.release
debuggable false
zipAlign true
}
debug {
packageNameSuffix ".debug"
debuggable true
runProguard false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(dir: 'libs')
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.code.gson:gson:+'
androidTestCompile files('libs/espresso-1.1-bundled.jar')
}
How do I solve this?
I had the same error.
As a temporary fix, you can add this in your manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19"
tools:replace="minSdkVersion, targetSdkVersion"/>
The tools namespace is declared as follow: xmlns:tools="http://schemas.android.com/tools". The downside of this fix is that you have to keep build.gradle and the manifest in sync with the value in minSdkVersion and targetSdkVersion. Hopefully it will be fixed in 0.10.1.
Looks like it was fixed in 0.10.4