Android Studio Build stuck when minifyEnabled is true - android-studio

Android Studio Generate Signed Apk stuck at
app:transformClassesAndResourcesWithProguardRelease
ExcecuteTransform
it works when minifyEnabled is false
My app.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.ashishclasses"
minSdkVersion 21
targetSdkVersion 28
versionCode 3
versionName "1.0.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
shrinkResources false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.google.firebase:firebase-firestore:18.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
// implementation files('libs/YouTubeAndroidPlayerApi.jar')
implementation "com.vimeo.networking:vimeo-networking:1.1.3"
// implementation 'com.mcxiaoke.volley:library:1.0.18'
// implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:9.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
// implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.google.firebase:firebase-ads:17.1.2'
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'
}
apply plugin: 'com.google.gms.google-services'
I even removed all my proguard rules, Now proguard-rules.pro is just empty file
Please tell me how I can build apk while proguard enabled

I kept running my build and after 20 Minutes Finally
Gradle build finished in 20 m 45 s 428 ms
So kind of my problem is solved but not actually.
My simple build of signed apk takes 1-2 minutes and with minify enabled 20+ minutes
And my hardware's are not that bad,
I have 6gb ram and ssd and using on arch linux and AMD A8 processor

Related

how to get compileSdkVersion equal or higer than the options shown

I'm making an app with ads in it with AdMob: https://developers.google.com/admob/android/quick-start?hl=he.
In order to that I need a "compileSdkVersion 28 or higher", so when I tried to change it by doing:
right-click on "app" > open module settings > compile SDK version, I was shown that the maximum option is: compile SDK version 27, and not 28 the minimum requirements for Google AdMob
also here is my build.gradle(Module: app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.admin.minesweeperyannai"
minSdkVersion 21
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 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
implementation 'com.google.android.gms:play-services-ads:19.4.0'//Google AdMob dependency
}
Also, I checked on their website and found out that I cant use lower versions than 19.4.0 or 18.1.0 (I didn't understand which one is the minimum but both of them didn't work).
This is the error I get when I try to use one of those versions:
error: failed linking references.
And I know my code is good because I've tried using the version: "play-services-ads 17.1.1" and it worked but only with test ads and not real ads, so to sum up I would like to know how to get Compile Sdk Version 28 or higher in order to show ads on my app.
This menu showing you the versions that you already installed it
so to get version 28 or 29 you need to install it
The first option is to change it from build.gradle file for example
android
compileSdkVersion 29
defaultConfig {
.....
minSdkVersion 21
targetSdkVersion 29
}
....
}
Or from SDK Manager select show package details and install Android SDK Platform 28 or 29 then select it from the Compile Sdk Version menu

shadow jar to avoid dependency duplication in android studio

I am building an android application in android studio but am having trouble with duplicate dependencies.
Duplicate class javax.inject.Inject found in modules jetified-javax.inject-1.jar (javax.inject:javax.inject:1) and jetified-javax.inject-2.5.0-b42.jar (org.glassfish.hk2.external:javax.inject:2.5.0-b42)
Both these dependencies were quite useful to me and i tried excluding the offending part of the dependencies from either of them which just ended up breaking one or the other.
I have been reading about shadow jars which from what i heard of sounded like a magic bullet so i tried it. From what i had read and heard you just added it as a dependency and it magically fixed everything. I tried adding it and i was still getting the error but i read online it is necessary to have the java or groovy plugin if you want it to work with out a lot of work. Either of these makes android studio very unhappy as android has its own slightly modified java or something.
Advice on how to get the shadow jar working would be much appreciated, but also if anyone has any other work arounds that would let me keep using the two clashing dependencies i would love to hear. I sorry if i made some newbie mistakes.
My gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.example.scrood"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.github.jengelman.gradle.plugins:shadow:6.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.squareup.picasso:picasso:2.5.1'
implementation 'org.glassfish.jersey.core:jersey-client:2.27'
implementation 'org.glassfish.jersey.media:jersey-media-json-jackson:2.27'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.10.4'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.4'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation ('com.google.android.libraries.places:places:2.3.0')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

isuess sync gradle for some old project from git

ERROR: Could not find com.android.tools.build:gradle:3.4.1. Searched
in the following locations:
https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.jar
Required by:
project : Add Google Maven repository and sync project Open File Enable embedded Maven repository and sync project
i have try to update distributionUrl
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
and this my build gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.android.miwok"
minSdkVersion 15
targetSdkVersion 29
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'
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:support-v4:$supportVersion"
implementation "com.android.support:design:$supportVersion"
}
well this is not best practice to do that, first of all, run that project in android studio and update the gradle, follow one method from this link Link.

can't get gradle to accept java-client-6.0.0-BETA1.jar in android studio 3

I'm new to android studio. I'm trying to get Android Studio Gradle to build with appium's java-client-6.0.0-BETA1.jar. I'm implementing appium. I believe android studio is install right. I've downloaded the recommended files for appium, selenium-server-standalone-3.8.1.jar, selenium-remote-driver.jar, selenium-java-3.8.1.zip and anything else I can see needed. Appium server is installed and working. An android emulator is running and working.
I get this error:
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Repositories\ApkProjects\EndToEndAndroidTest\app\libs\java-client-6.0.0-BETA1.jar
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:550)
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.lambda$convertToDexArchive$1(DexArchiveBuilderTransform.java:488)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing io/appium/java_client/touch/TapOptions.class
The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
I've tried the recommended fix - makes no difference. I've updated guava-23.3-android also which was giving similar errors.
The gradle.build file is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.nwri.endtoendandroidtest"
minSdkVersion 18
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 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
// compile 'com.google.guava:guava:23.3-android'
}
I've searched the web and can't find anyone having this issue. Here is a screen shot if that helps:
Android studio
Setting Source Compatibility and Target Compatibility to 1.8 in Project Structure dialog helped me.
While manual adding
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
did not help.

Decompiling a self generated jar in lib in Android Studio

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.github.triplet.play'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.prototype"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled = false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.10.19"
testCompile 'org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:0.31'
}
I have generated a jar using swagger codegen and have placed in lib folder of my app in the Android studio. It is not getting decompiled, i.e., I am not able to see classes of my jar here.
I have tried Invalidate caches/Restart. It worked sometimes before.
But it is not working anymore. Any help will be appreciated.
You probably missing in your build.gradle something like:
compile files('libs/your-jar-filename.jar')
The following worked for me :
Right-click the jar file.
Select 'Add as Library.
Do Gradle Sync.

Resources