Issue in making APK file in Android studio - android

I'm working on my very first android application which is almost complete now and ready to post on play store. But I'm unable to make the APK file :(
I'm using Android Studio 3.0.1
gradle-4.1
When I tried to make the APK file I got the error:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
which was quickly resolved by adding multiDexEnabled true to
app/build.gradle
file. But after adding this I'm now getting another error:
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> java.io.IOException: Can't write [D:\My Data\Android\1stApplicationTest\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\USER_NAME\.gradle\caches\transforms-1\files-1.1\support-media-compat-26.0.2.aar\d7c069de85684fc017734fd1ac5ba973\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/v4/media/VolumeProviderCompat.class]))
I'm unable to resolve this issue I tried number of solutions
updated all the jars version as per build/sdk version of the application
Removed duplicate/extra dependencies, if any
Removed Build folders from root and inside of app folder
In Android Studio File -> Invalidate Caches/Restart
Restarted Android studio with the clean build, also removed extra jars in .idea folder
Please advise if i need to remvoe something from the SDK: C:\Users\USER_NAME\AppData\Local\Android\sdk
Here is app/build.gradle file of my application
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId 'Shah.Jee'
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.0.2'
/*
compile files('libs/android-support-v4.jar')
compile 'com.android.support:support-v4:26.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:26.0.2'*/
compile 'commons-lang:commons-lang:2.6'
compile 'com.github.bumptech.glide:glide:4.2.0'
compile 'com.google.android.exoplayer:exoplayer:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-core:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-dash:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-hls:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-smoothstreaming:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-ui:r2.4.0'
testCompile 'junit:junit:4.12'
compile project(':picasso-2.5.2')
}
Need a quick advise if I'm missing something. Thanks in advance.

Related

Include external libraries in your .aar file (a plugin for Unity)

I came across a problem while implementing an Android plugin for Unity based on EasyPermissions. The issue was due to
Caused by: java.lang.ClassNotFoundException: Didn't find class "pub.devrel.easypermissions.EasyPermissions$PermissionCallbacks"
as the relevant classes were not packed by Android Studio into my AAR file.
I tried various ways:
Just compile in Android Studio and hope the resulting AAR will be fine FAIL
Download an AAR from jCentral and add it to Unity - FAIL
So finally I unzipped the EasyPlugin AAR and took the classes.jar file thats inside and added this to Unity. This worked. Yet its quite a manual process.
What is the tinly little bit I need to add to my gradle file to get this done automatically?
I am using:
https://github.com/googlesamples/easypermissions
Unity 2017.1 (should not matter)
Android Studio 2.3.3
Gradle task used: build->assemble
My Gradle File:
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion "27.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
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(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:26.+'
testCompile 'junit:junit:4.12'
compile 'pub.devrel:easypermissions:1.0.1'
provided files('unity/classes.jar')
}
PS. There was a second issue when overriding UnityPlayerActivity but for that a clause provided instead of compile was the solution.
Check above comments.
If you use an external library its enough to add its AAR into Plugins/Android directory in Unity.
For some reason I added it in a way that went unnoticed by Unity and Unity was not adding it into resulting APK file.

ERROR with Gradle build in Android Studio

Every time I load a project I get the following errors, and I have tried everything that I have found on the internet to resolve these errors such as
Deleting .gradle file in users folder and letting android build it again.
I have tried the re validating cache and restarting it.
Re downloading Android Studio after uninstalling previous version.
I have tried numerous anwsers that have helped a lot of people, but it still does not work for me.Basically it's all my dependices. Yesterday i opened a friends project to put it on his kindle to demo for the lecturer but all it did was destroy my android studio. can anyone help please?
Error:(33, 13) Failed to resolve: com.android.support:support-vector-drawable:25.0.1
Install Repository and sync projectShow in File
Show in Project Structure dialog
Error:(24, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:2.2.2
Install Repository and sync project
Show in Project Structure dialog
Error:(24, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:2.2.2
Install Repository and sync project
Show in Project Structure dialog
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "ie.wit.fitnessmadeeasy"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
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.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.android.support:support-vector-drawable:25.0.1'
testCompile 'junit:junit:4.12'
}
You need to install the support repository, as described here:
Start the Android SDK Manager.
In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder and, if necessary, expand to show its contents.
Select the Android Support Repository item.
Click the Install packages... button.

Fixing A Run Time Error for An Android Program

when I was trying to run a simple program , I got an error related to Gradle :
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration':app:_debugUnitTestCompile'.
> Could not resolve junit:junit:4.12.
Required by:
MyApplication:app:unspecified
> Could not resolve junit:junit:4.12.
> Could not get resource 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
> Could not GET 'htps://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
> Connection to htps://jcenter.bintray.com refused .
I don't know how can I fix it , please help .( I am currently using the android studio version 2.1.2 )
my module build-gradle includes these codes:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.n5110.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.3.0'
compile 'com.android.support:design:23.3.0'
}
The problematic part with your gralde.build is this line:
testCompile 'junit:junit:4.12'
This is a unit testing library. If you are just starting and are probably not gonna write testcases for your project then, you can resolve the issue by simply deleting the line. If however you essentially need that library then refer here.

Android Studio Error: Failed to find build tools revision 24.0.0 rc4

I cloned a project from github, and I have the following error in the Build: Failed to find Build Tools revision 24.0.0 rc4. This is the build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '24.0.0 rc4'
defaultConfig {
applicationId "com.project02.projects"
minSdkVersion 16
targetSdkVersion 23
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:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.android.gms:play-services:9.0.1'
compile 'com.google.android.gms:play-services-ads:9.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
compile 'com.android.support:support-v4:23.4.0'
}
I have In File->Project Structere -> Build Tools Revision -> 24.0.0 rc4. And in the SDK directory the folder is 24.0.0-rc4.
I tried to change to 23.0.2, but with that I obtain this errors in the Run: **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** and
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
The error you're getting is because you're overriding the previous built tool with the new one that doesn't exist in your built-tools folder.
Make sure you download the intended built tool from the SDK manager and then configure the gradle file appropiately. Check and see if that works.
It works for me.
I run "./gradlew build" on commandline and change buildToolVersion "24".
While the command is running, the SDK will be installed and everything goes OK.

Error in generated values-23 file in Android

I am getting this error when I try to build my project.
Error:(3, 5) No resource found that matches the given name (at 'cardBackgroundColor' with value '?android:attr/colorBackgroundFloating').
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Home\AppData\Local\Android\sdk\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1
And when I click on it it takes me to the v-23 values file of generated folder which contains following code.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CardView" parent="Base.CardView">
<item name="cardBackgroundColor">?android:attr/colorBackgroundFloating</item>
</style>
</resources>
This is my app gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.xxxx"
minSdkVersion 19
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.commit451:inkpageindicator:1.0.2'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'ch.acra:acra:4.5.0'
compile 'com.pkmmte.view:circularimageview:1.1'
compile 'com.google.android.gms:play-services-maps:7.8.0'
compile 'com.google.android.gms:play-services-location:7.8.0'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.google.code.gson:gson:2.6.2'
}
And when I change everything in gradle to version 23 this error goes away but as I am using http libraries and they are removed from 23 version therefore I am forced to use 22 version. My project was working perfectly fine before and at a sudden it started giving this error. Only thing I done was install a support repository which I was using in other project and it start giving error in this project too.
Any way to resolve this error?
compile 'com.facebook.android:facebook-android-sdk:4.+'
needs V-23
In my case I use v-22 so
i changed Facebook sdk version to 4.8
compile 'com.facebook.android:facebook-android-sdk:4.8.0'
That error makes perfect sense, seeing as ?android:attr/colorBackgroundFloating
was only added in API 23 and you are using compileSdkVersion 22.
So, to fix the error, you need compileSdkVersion 23 to include that resource in your build. Also, having a v23 values file doesn't make sense when you have targetSdkVersion 22, which says you aren't targeting v23 devices anyways.
And you mentioned the "http libraries" you are using are gone? If you are referring to HttpClient from the org.apache package, then you can add it back by including this in your build.grade
android {
useLibrary 'org.apache.http.legacy'
}
if you dont want to upgrade your modules,in addition solution is excluding modules in build.gradle with compile tag
compile( 'com.facebook.android:facebook-android-sdk:4.11.0')
{
exclude module: 'cardview-v7'
}

Categories

Resources