I have a build problem with Android Studio in a new project I've recreated. Please follow what I've done and if anyone has any idea how to proceed, do tell!
I started a new project, selecting 'Navigation Drawer Activity' as my initial start-point (could be anything I guess).
I instantly built my new 'empty' app and debugged it on a real device (a nexus 9). All runs fine.
I then added an office-file-creating library I want to use for creating xlsx files, so I added the following line to my build.gradle app file (in dependencies):
compile 'org.apache.poi:poi-ooxml:3.13'
I resync and it builds ok (within seconds). I then attempt to debug this on a real device but it doesn't build anymore (takes 10x longer to attempt build) and I get an error:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 1
I looked this up and every place I look people are telling others to use "multiDex". I understand this applies if you are exceeding 65K methods. I guess with the POI library I might well be exceeding that. After finding no other alternative course of action I implemented multiDex by adding the following lines to my build.gradle app file:
multiDexEnabled true
compile 'com.android.support:multidex:1.0.1'
and adding the following line to my Manifest file:
android:name="android.support.multidex.MultiDexApplication"
I assume I've implemented the multiDex ok. The app builds ok but when I attempt to debug it I am met with this error (takes about 7sec to get here):
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/xmlbeans/xml/stream/Location.class
No other files were tampered with. If I remove the compile POI library line from build.gradle then all is ok. I put the library back in, it fails in the same way.
I've tried to figure out how to tell it to ignore the duplicate library in xmlbeans (again other posts tell coders this is what needs to be done) but I'm not sure how to do that and if that is the best way forwards ie should I still be multiDex'ing?
It's taken me a few days on-and-off to get this far and it's my first time using Android Studio - migrating away from Eclipse because I'm fed up of not being able to build my apps for days for no good reason.
Someone who knows what this all means... help me please!
Edit: I have cleaned & rebuilt the project and also tried deleting the build files but to no avail.
Program stats:
Android Studio 1.5.1
Build #AI-141.2456560, built on December 1, 2015
JRE: 1.8.0_25-b18 amd64
JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation
Gradle ver: 2.8
Android plugin ver 1.5.0
'build.gradle' app file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.kane.testproject"
minSdkVersion 15
targetSdkVersion 23
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.1.1'
compile 'com.android.support:design:23.1.1'
compile 'org.apache.poi:poi-ooxml:3.13'
compile 'com.android.support:multidex:1.0.1'
}
'AndroidManifest.xml' file
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.kane.testproject"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Add the following lines in build.gradle(Module app)
dexOptions {
javaMaxHeapSize "2g"
}
Related
I was following this tutorial from youtube to learn to make an android keyboard. I followed everything as described in it. I was able to build the project succesfully but whenever I try to run it I was getting the following error -
Instant Run performed a full build and install since the installation on the device does not match the local build on disk
So I googled for a solution and tried turning off Instant Run, then the above mentioned error was not appearing. The APK was installed to my device, but when I tried to enable the keyboard in the settings it was not found there. I tried it in device and 2 emulators, but problem is same everywhere.
I don't know what to do. I will copy my Android Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tomsapp.keeskeyboard">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<service
android:name=".KeesKeyboard"
android:label="#string/app_name"
android:permission="android:permission.BIND_INPUT_METHOD">
<meta-data android:name="android.view.im" android:resource="#xml/method"/>
<intent-filter>
<action android:name="android.view.InputMethod"/>
</intent-filter>
</service>
</application>
and Build Gradle file here:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.tomsapp.keeskeyboard"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Please point out what I am doing wrong here.
In your build.Gradle file set minSDK to 22n so it matches your android vertual device.
If there is an image view in your app then place that image Corresponding to image view in the drawable folder. Don't keep it in drawable -v24 folder and run on your device it may work
I am not sure why this is happening, but I did some digging and tried to find other solutions. None worked out especially duplicate questions:
android {
compileSdkVersion 26
buildToolsVersion "23.0.3"
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
defaultConfig {
applicationId "com.myapp"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':react-native-customized-image-picker')
compile project(':react-native-vector-icons')
compile project(':react-native-restart')
compile project(':react-native-image-picker')
compile project(':react-native-fast-image')
compile project(':lottie-react-native')
compile project(':react-native-fetch-blob')
compile "com.android.support:multidex:1.0.1"
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.fresco:fresco:1.0.1"
compile "com.facebook.fresco:animated-gif:1.0.1"
compile("com.facebook.react:react-native:0.54.0") { force = true } // From node_modules
}
I deleted some duplicate compiles that I found and still no help. I noticed in the trace this warning:
C:\ReactProjects\myapp\android\app\src\main\AndroidManifest.xml:11:5-29:19 Warning:
application#android:theme was tagged at AndroidManifest.xml:11 to replace other declarations but no other declaration present
C:\ReactProjects\myapp\android\app\src\main\AndroidManifest.xml:16:9-19:35 Warning:
meta-data#com.bumptech.glide.integration.okhttp.OkHttpGlideModule was tagged at AndroidManifest.xml:16 to remove other declarations but no other declaration present
I don't know if that will cause this whole thing to fail. Lastly here is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="true"
tools:replace="android:theme"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
Every problem that I had when trying to get a successful build I looked on SO or other sources, but this one takes the cake. I never inserted compile "com.android.support:multidex:1.0.1" before and it worked before this problem occurred. Still no success.
The last thing I remembered doing is saving a file called 'safecode.js' in the home directory and basically it just has code that I want to save.
I had the exact same problem and I understand what a headache this can be. Here was my solution:
1) Make sure there are no duplicate dependencies in build.gradle and settings.gradle
2) Most of you might not like this one, but I (hurts to type this) upgraded most things such as:
compileSdkVersion 26 - build.gradle
buildToolsVersion "26.0.1" - build.gradle
distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip - settings.gradle
classpath 'com.android.tools.build:gradle:3.1.0' - build.gradle not in app directory
NOTE: Your Command Prompt's build UI will change and it does look overwhelming, but pretty cool. You'll get used to it. Also, you might need to change those compile in build.gradle soon.
Here is the solution for that: Android Studio build.gradle warning message
That should be pretty much it, but I'll also tell you other things I did that might affect your BUILD FAILED:
1) You might need Java 8. JDK 1.8. Add this to build.gradle app directory:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
2) Get rid of compile "com.android.support:multidex:1.0.1"
3) targetSdkVersion 22 update to 26
And lastly,
4) In build.gradle not in app directory, put maven { url 'https://maven.google.com' } in both repos.
NOTE: You could use google() in place of that, but it didn't work for me so I stuck with maven { url 'https://maven.google.com' }.
ALSO TO NOTE: You might get messages saying, "WARNING: The specified Android SDK Build Tools version (26.0.1) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.0.". Hey, 26 seems to be our magic number, if it works, then don't touch it. Unless you are absolutely certain you need to.
To my knowledge and experience the warnings you get from the build process won't affect your BUILD SUCCESS or BUILD FAILED.
I hope this works for everyone!
I'm relatively new to Android programming and I am trying to create a Google Maps project. I used the template option in Android Studio, and I added the key for the API.
I haven't added any of my own code and left the template code as is because I just wanted to run the code and see what it looks like, however, I keep getting a multi dex error when I try to run this on the emulator causing the build to fail. It's weird to me that I am getting this error because I haven't added ANY code at all and am using what the Google Maps template has from Android Studio.
Anyone know why this error shows up on a brand new project? The error I see is pasted below.
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_91\bin\java.exe'' finished with non-zero exit value 2
as quoted below:
Your probably compiling all of the play-services API's using compile 'com.google.android.gms:play-services:9.2.0'... Now we can selectively compile API's to avoid dex limit of 64K. For Google Maps use com.google.android.gms:play-services-maps:9.2.0... – Loki Jul 1 at 19:01
Answer from Loki worked and was very simple to do.
setting up google play services
Go through this link just add the dependencies which you want in your application.
This will prevent 64k exceeding error.
Happy coding.
For those who tried all the above methods and failed. Try changing the mini sdk version to 21 in the build.gradile file. For me it was on 16 and when I changed it to 21 the multidex error was gone for good.
minSdkVersion 21
The issue is you currently have a high number of methods. There can only be 65536 methods for dex. You can try enabling multiDex by editing your build.gradle file.
android {
//stuff
defaultConfig {
...
// Enable multiDex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Also, oops as the poster above mentioned in your manifest you also need to add that you are using the multidex class from the multidex support library.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.dexapp">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
Change your Gradle build configuration to enable multidex
android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc2"
defaultConfig {
applicationId "com.try.app"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
In your manifest add the MultiDexApplication class from the multidex support library to the application element.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Note: Visit https://developer.android.com/studio/build/multidex.html for more info.
Set property multiDexEnabled to true in defaultConfig. This error occurs when method references increase the limit of 65k. Check Google Play Service APIs.
android{
...
defaultConfig {
...
multiDexEnabled true
}
...
}
Here is a good source to get started with Google Maps Android API
I removed the dependencies as suggested by Loki and it works.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.google.android.gms:play-services-maps:9.4.0'
}
The app I am developing works perfectly on my emulator, but it won't work on my phone when I try to debug it. I only get the message:
Warning: debug info can be unavailable. Please close other application using ADB: Monitor, DDMS, Eclipse
Restart ADB integration and try again.
Waiting for process: com.deliciouslymad.tsukasa.critterbytes
It hangs there forever with no change on my phone. It doesn't work after restarting or cleaning the project, either. I've tried many solutions on this site already, but none of them have resolved this issue.
-UPDATE-
ADB logs:
ddms: null
java.lang.NullPointerException
at com.android.ddmlib.Client.sendAndConsume(Client.java:673)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:195)
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:66)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:772)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
The .apk installs on my phone just fine.
I have 'USB debugging', 'allow mock locations', and 'verify apps over USB' turned on in my phone settings. Runtime is Dalvik and it's connected as a media device.
My phone runs Android 4.4.4.
If it helps, I am implementing the Zxing library into my code for barcode scanning.
Here's my AndroidManifest.xml code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deliciouslymad.tsukasa.critterbytes">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name="ScannerActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here's my build.gradle code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.deliciouslymad.tsukasa.critterbytes"
minSdkVersion 16
targetSdkVersion 21
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.1.0'
}
Additionally, in my app's project structure, the 'Compile Sdk Version' is API 21 and the 'Build Tools Version' is 21.1.2. 'Source Compatibility' and 'Target Compatibility' are blank, and I'm not sure if anything is supposed to be there.
The gradle builds fine with no errors, but there is something strange; when I hover over 'getDefaultProguardFile' in the build.gradle file, it says that it cannot resolve the symbol.
I am a junior programmer and trying to learn, so please let me know if there's anything missing or anything I can improve! This is all a little overwhelming and I can't figure out why it's not working.
After 6h spent trying to fix this by myself, AS is driving me crazy. Everything was fine yesterday and today it can't resolve any of the support libs nor the R symbols.
I tried everthing, including all the suggested fixes I found on StackOverflow. No need to tell me to have a look a this post, I already have and none of the solutions work.
Here's what I tried so far :
rebuilding / cleaning the project (many times...),
synchronising the project with Gradle Files,
check that the support lib is up-to-date in the SDK Manager,
invalide Caches / restart AS,
delete the .idea folder and the .iml files of my project, and re-importing it in AS,
update AS from 0.8.11 to 0.9,
eventually I ended up uninstalling AS and reinstalling it from scratch
And none of this fixed my issue...
Something really weird is that I also tried to create a whole new project from scratch and to copy/paste all my classes & resources from my corrupted project to this new one. And it worked for a while (~10 min), until it eventually became corrupted the same way, without any apparent reason.
Moreover, no idea if it's relevant, but when I type "ViewPager" in AndroidStudio and hit CTRL-SPACE, it doesn't suggest me the "android.support.v4.view.ViewPager" class. But if I hit CTRL-SPACE 3 times in a row, it DOES suggest it. So I guess that means that it's able to find the support lib somewhere but not to use it?
Here's my build.gradle :
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.mathieumaree.library"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:support-v13:21.0.0'
}
Please, help me, otherwise I'm gonna break my computer soon.
Thanks in advance,
Mathieu
EDIT 1 :
I forgot to mention that this occurs only in one of my projects. The others seem to be fine (at least for now).
EDIT 2 :
I also forgot to mention that my project is composed of an application project plus a library module inside it. So here is the app's build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.mathieumaree.materialheaderviewpager"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.android.support:support-v13:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
}
The app Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mathieumaree.materialheaderviewpager" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.mathieumaree.materialheaderviewpager.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The library manifest :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mathieumaree.library">
<application android:allowBackup="true"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
</application>
</manifest>
The main settings.gradle :
include ':app', ':library'
And the main 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:0.14.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
EDIT 3 :
After trying once more to delete all .idea folers & *.iml files and reloading my project, I noticed that AndroidStudio displayed an error at openning :
Accessing invalid virtual file:
file://C:/Users/Mathieu/AppData/Local/Android/android-studio1/sdk/sources/android-21;
original:582; found:-: Accessing invalid virtual file:
file://C:/Users/Mathieu/AppData/Local/Android/android-studio1/sdk/sources/android-21;
original:582; found:-
I'm pretty sure it means it's looking for the SDK to yet another location (AppData/Local...android-21). What I don't understand is :
there's no SDK folder at this location
the SDK path indicated in the Project Structure is not this one
Any idea what all this means?
try addind this to buid.gradle
compile 'com.android.support:support-v4:21.0.0
and change build tools version to 20.0.0
Also create a whole new project and see if the same errors are still present in that project.
Try "Tools" -> "Android" -> "Sync Project with Gradle Files"
Well, still not a clue what caused this problem but it would look like I managed to get rid of it, although I had to create a new project from scratch. What I really don't understand is that I've already done this yesterday and it didn't work out.