Problems importing an Eclipse project into Android Studio - android

I created my first Android app 2 years ago in Eclipse and now I have some time to improve it. I do not have Eclipse installed anymore, so I decided to import the project into Android Studio.
But now I am running into several problems:
Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version 14 declared in library [com.google.android.gms:play-services:10.2.0]
So in the build.gradle I changed it to 14. Then I got the next error
Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Spinner.Underlined'.
So therefor I changed the compileSdkVersion and the targetSdkVersion to 25 (correct me if it's wrong). And I changed
compile 'com.android.support:support-v4:20.0.0'
into
compile 'com.android.support:support-v4:25.2.0'
Now I could build my project. But when I tried to run my app, after more then 5 minutes(!) I got the next error :
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
So then I added
multiDexEnabled true
and
compile 'com.android.support:multidex:1.0.1'
and
android:name="android.support.multidex.MultiDexApplication"
to the manifest file.
My build.gradle now looks like this
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "<<myApplicationId>>"
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:25.2.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/AppFireworks.jar')
compile files('libs/fcvtgzwtzuliivdcu.jar')
compile 'com.android.support:multidex:1.0.1'
}
But now I got the following pop-up and errors
Instant Run does not support deploying build variants with multidex enabled, to a target with API level 20 or below. To use Instant Run with a multidex enabled build variant, deploy to a target with API level 21 or higher.
Error:UNEXPECTED TOP-LEVEL ERROR:
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
What have I done wrong? Do I have to change the minSdkVersion to 21? I want to be able to run my app on Android 4.x. I could when I was developing in Eclipse. So far switching from Eclipse to Andriod Studio is going from bad to worse. :-(

you are compiling using compile 'com.google.android.gms:play-services:+'
play service is itself is a large library. You should not use + which implies all available version to compile
Rather use a specific version of play services or break down the library and use specific services like location,maps etc.
Also u can use dexOptions to increase ur memory usage during compilation
try changing your gradle file to:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "<<myApplicationId>>"
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:25.2.0'
compile 'com.google.android.gms:play-services-maps:9.0.1'
compile 'com.google.android.gms:play-services-plus:9.0.1'
compile 'com.google.android.gms:play-services-location:9.0.1'
compile 'com.google.android.gms:play-services-games:9.0.1'
compile 'com.google.android.gms:play-services-gcm:9.0.1'
compile files('libs/AppFireworks.jar')
compile files('libs/fcvtgzwtzuliivdcu.jar')
compile 'com.android.support:multidex:1.0.1'
}

Related

app:transformClassesWithJarMergingForDebug can't resolve

I have this error whenever i try to create an APK for the app.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/text/TextUtilsCompat.class
The app run in the android emulator , but when i try to build an apk i get this error.
i dont know what to change
here is the gradle code
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.companyname.gamename"
minSdkVersion 11
targetSdkVersion 23
multiDexEnabled true
ndk {
moduleName "player_shared"
}
}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/support-v4-19.0.1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
}
I tryed to clean rebuild an run the prject but i still have the same problem,
I've read that it's depencdencies problem. but can't figure wich one to remove.
First, never use a plus dependency.
services:+'
Also don't compile all the Play Services, only setup ones you really need.
https://developers.google.com/android/guides/setup#split
Secondly, stop using jar files and go find the correct libraries using Maven Central (or the supporting documentation for those libraries) and use the other way to compile through Gradle.
Your jar files have overlapping classes and therefore you have errors
While you're at it...
Dagger 1 is being deprecated for Dagger 2
NineoldAndroids has stopped being maintained, so best to find some other way to use the code you need it for
Your support libraries need to match the compileSdk version

Failed to run my android application because a level 21 app generate level 23 files

Here my build.gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mycompany"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
debuggable false
signingConfig signingConfigs.config
minifyEnabled true
zipAlignEnabled true
proguardFile 'proguard-rules.pro'
}
debug {
debuggable true
signingConfig signingConfigs.config
}
}
}
dependencies {
compile 'com.facebook.android:facebook-android-sdk:3+'
compile 'com.android.support:support-v4:+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.android.gms:play-services:+'
compile 'com.github.codechimp-org.apprater:library:1.0.+'
compile 'com.mcxiaoke.volley:library:1.0.+'
compile files('libs/disklrucache-2.0.2.jar')
compile files('libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/socialauth-4.2.jar')
compile files('libs/socialauth-android.jar')
}
I can compile my source code without problem but get the following error message when I try to run:
/Users/myname/Projects/myproject/build/intermediates/res/merged/release/values-v23/values-v23.xml
Error:(4) Error retrieving parent for item: No resource found that
matches the given name
'android:TextAppearance.Material.Widget.Button.Inverse'. Error:(34)
Error retrieving parent for item: No resource found that matches the
given name 'android:Widget.Material.Button.Colored'. Error:Execution
failed for task ':project:processReleaseResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command
'/Users/myname/.android-sdk/build-tools/21.1.2/aapt'' finished with
non-zero exit value 1
I really don't understand. My compiledSdkVersion and targetSdkVersion is 21 and I even don't have a file called values-v23. Why got this error? Can anybody help? Thanks.
Edit 1:
#Gabriele Mariotti's answer solved this problem. But here comes another problem.
Error:Execution failed for task '::transformResourcesWithMergeJavaResForRelease'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/org.brickred/socialauth/pom.properties
File1: /Users/xxxxxx/libs/socialauth-4.2.jar
File2: /Users/xxxxxx/libs/socialauth-4.2.jar
What could be the reason? I checkd there is of course only one socialauth-4.2.jar in my libs folder.
Since you are using
compile 'com.android.support:support-v4:+'
compile 'com.google.android.gms:play-services:+'
you are using the latest versions which has a dependency with support libraries v24.
You have to use compileSdkVersion 24
In general it is not a good idea to use this kind of dependencies (+) because you will not be able to reproduce the build in the future (since the dependencies will change)
You have a resource file which is specifically targeted to API 23. You can either remove this file or change compileSdkVersion to 23. The later is preferable since your app will still be able to run on devices with versions of Android prior to level 23.

To run dex in process, the Gradle daemon needs a larger heap. It currently has 910 MB

Actually the main error is "java.exe finished with non-zero exit value 1". First i tell you every problem which i faced after installing studio:
Three days ago, i just installed android studio & I created new project.
1) First it throw the error "Plugin is too old, please update to more recent version", after searching on google i changed
classpath : com.android.tools.build:gradle:2.0.0-alpha2
to
classpath : com.android.tools.build:gradle:2.0.0-alpha8
Current Error solved.
2) After that it was asking for gradle 2.10, i updated this one also & set the path.
Current Error solved.
3) When i ran my application i got one more error "app-debug-unaligned.apk, specified for property 'input file' does not exist".
I searched on internet, i got one solution on stackoverflow. So as answer on stackoverflow i go to "Build" & i selected build apk.
Current error solved.
4) But after that again i got one error
"To run dex in process, the Gradle daemon needs a larger heap. It currently has 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 1G.
java.exe finished with non-zero exit value 1".
I have been searching on stackoverflow for last three days, i applied each and every answer one by one but i'm not able to solve the error. Please save my life, i am really tired of this problem. I show you image what error is coming exactly
My build.gradle file
apply `plugin: com.android.application`
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "java.danish.org.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
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'
}
I updated everything SDK platforms & SDk Tools.
Please tell me what i am doing wrong here.
Issue
In gradle plugin version 2.0.0-alpha7 and -alpha8 Dex runs inside gradle build process as opposed to a separate process.
Option a)
Change gradle plugin version to 2.0.0-alpha9 where in-process Dex is disabled by default.
classpath 'com.android.tools.build:gradle:2.0.0-alpha9'
Option b)
Disable in-process dex in your app module build.gradle:
android {
// ...
dexOptions {
dexInProcess = false
}
}
Option c)
Increase memory available to gradle process.
Create or update gradle.properties file in your project root directory:
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=512m
And update your app module build.gradle file:
dexOptions {
preDexLibraries true
javaMaxHeapSize "3g"
incremental true
dexInProcess = true
}
These values are experimental and work for my setup. I use 3 GB for dex and 4 GB for gradle (3 + 1 GB).
Note
If you have any issues update to alpha9 anyway.
I found the solution.
Changes
1)
dexOptions {
javaMaxHeapSize "4g"
}
2)
lintOptions {
checkReleaseBuilds false
abortOnError false
}
This is my new build.gradle and everything is working fine now.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc4"
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.aquasoft.guesp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.squareup.picasso:picasso:2.5.0'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.android.support:design:23.4.0'
compile 'com.stripe:stripe-android:+'
compile 'com.roomorama:caldroid:3.0.1'
compile 'com.android.support:cardview-v7:23.3.+'
}
try this gradle params
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry issue

I am struggling to run a basic Mapsforge application. I have added all its required jar files to project and gradle. But i am not able to run application. Getting following error:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry: org/mapsforge/map/reader/Way.class
Here is my gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "test.mapsforge"
minSdkVersion 14
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'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile files('libs/mapsforge-core-0.5.1.jar')
compile files('libs/mapsforge-map-0.5.1.jar')
compile files('libs/mapsforge-map-android-0.5.1.jar')
compile files('libs/mapsforge-map-awt-0.5.1.jar')
compile files('libs/SwingMapViewer-0.5.1.jar')
}
Folder structure
I have tried adding multiDexEnabled true in gradle config but didnt worked
Is there a reason you need to multidex? The decencies seem somewhat scarce and unless they are packed with methods I don't see how you would get past the 65k method limit. I also don't see a dependency for compile 'com.android.support:multidex:1.0.0' Please check https://developer.android.com/tools/building/multidex.html or try not using ultidex. You also may need to extend MultiDexApplication instead of a regular Application. I think your issue is really a duplicate dependency and not aa dex limit. have you tried gradle :app:dependencies?
I face same error too. when I delete swing map viewer every thing work fine even without using multiDexEnabled true

Gradle: Execution Failed For Task

Hi I just tried to do a example program of Android Tab Layout With Swipe. I added android support libraries in the lib folder. I added appcompat v4 and v7 in that. After that I clicked sync project with gradle files. Then I entered code then everything went and I found no error in code but when I try to run the program its showing me this error
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/annotation/ArrayRes.class
And my build.gradle file contains this
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.eugene.swipeabletablayout"
minSdkVersion 15
targetSdkVersion 21
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:appcompat-v7:22.0.0'
}
In my code there is no problem but I don't know why I am getting this error.
I tried to search for this issue in SOF but I didn't find any answer.
Remove the Android support libraries from the libs directory. Since you are using gradle and have indicated a compile dependency with appcompat-v7 you do not need to include the JARs manually. This is causing a conflict at build time with duplicate symbols. Listing it as a compile dependency will cause gradle to work with Maven to pull the lib automatically (and its dependencies.)

Categories

Resources