问题
I got an error building android project, even a hello world project:
Console output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/19.1.0/dx --dex --output /Users/luyaochen/Documents/and/MyApplication3/app/build/intermediates/pre-dexed/debug/internal_impl-20.0.0-20e875ec0585f022fce03f5b07d31a0222ca3f58.jar /Users/luyaochen/Documents/and/MyApplication3/app/build/intermediates/exploded-aar/com.android.support/support-v4/20.0.0/libs/internal_impl-20.0.0.jar
Error Code:
1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
please help, I don't know what went wrong
回答1:
I had the same issue, found out that JDK location in project setting pointed to Java 8 directory. Changing it to Java 7 fixed the issue
回答2:
./gradlew assembleDebug
worked for me.
回答3:
In my case this problem was caused by a broken build tools version. In my build.gradle file, the build tools pointed to version "21.1.1"
buildToolsVersion "21.1.1"
That version was actually missing the dx.jar file. It probably happened during a messy upgrade to version 1.2 of Android Studio.
I solved the problem by changing build tools to version 22.0.1 which has the dx.jar file.
I found out when I changed the current directory to my SDK home, and searched for all dx.jar files. Notice that my current build tools version (21.1.1) has one.
glenns-mbp:sdk glennbech$ find . | grep dx.jar
./build-tools/18.0.1/lib/dx.jar
./build-tools/19.0.3/lib/dx.jar
./build-tools/19.1.0/lib/dx.jar
./build-tools/22.0.1/lib/dx.jar
回答4:
Steps to come out from preDexDebug error:
- goto file menu
- click on settings
- apperance and behavior
- system settings
- Android SDK
- select android sdk tools - check whether all tools are installed or not,if not installed then install them.
Come out and rebuild project and click on 'Run' menu. In that click on 'Debug app'. If it shows an error again, follow below steps
- click on "gradle scripts" => "build.gradle(Module:app)" => in that file under "default config function" => make both "minsdk version" and "targetsdk version"same.
- click on "sync project with gradle files icon" (icon looks like "arrow pointing downwards with green color")
- again rebuild and debug_app
I did these steps and i killed that error.
来源:https://stackoverflow.com/questions/25828524/android-studio-predexdebug-failed