apache commons ftp doesn't work on release build apk - android

I'm able to upload files to an FTP Server when I'm using a debug build, but it fails in the release build:
it fails regardless if minify is enabled or not
it fails even when I remove proguard settings
I am able to generate the release build apk with no errors. The upload-to-ftp feature in the app just won't work.
build.gradle
implementation 'commons-net:commons-net:3.6'
....
minifyEnabled false
shrinkResources false
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debuggable true
signingConfig signingConfigs.release
proguard-rules.pro
-keepclasseswithmembernames class * {
native <methods>;
}
-keep class com.integratedbiometrics.** { *;}
-keep class org.libusb.** { *;}
-keep class com.futronictech.** { *;}
-keep class com.smufsbio.btsdk.** { *;}
-keep class org.apache.http.** { *; }
-keep class org.apache.commons.codec.** { *; }
-keep class org.apache.commons.logging.** { *; }
-keep class android.net.compatibility.** { *; }
-keep class android.net.http.** { *; }
-dontwarn org.apache.http.**
-dontwarn android.webkit.**
What am I missing?

I got it working already. I found out it was not the shrinking and obfuscating at all because setting minifyEnabled and shrinkResources to true in both release and debug build still gave me an issue with the release build while the debug build worked well.
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
The only difference then was the signingConfig, and when I set
signingConfig signingConfigs.release
in the debug build, the problem surfaced in the debug build.
Apparently, there was something wrong with the security certificate I was signing the apk with. Creating a new certificate fixed the issue for me. It's the first release so there's no issue in doing so.

Related

After set minifyEnabled true in debug mode api call not working properly

After minifyEnabled true in build.gradle
Like below
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
When i make api call while minifyEnabled true i got success but some Parameters value change which is different from expected value.
And
When i make api call while **minifyEnabled false ** i got actual value which comes from back-end side.
(i.e.) i got isValidUser parameter in api response which is boolean
actual value is isValidUser=true which is expected but i got isValidUser=false.
help me what is the problem with my build.gradle file?
Please specify exactly what part is not working, but generally its from the models, so exclude them in the rules file as:
# Models
-keepclassmembers class com.example.models.** {*;}
# GSON
-keepattributes Signature
-keepattributes *Annotation*
-dontwarn sun.misc.**
-keep class com.google.gson.examples.android.model.** { *; }
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
with the help of Payam Kokabi,
issue is solved minifyEnabled true is will not change the value when we declare
-keep class YOUR CLASS ** { *; }
in your proguard-rules.pro file.
#Arbaz.in if you use #SerializedName and keep Gson you wouldnt need to keep your classes althought in some rare cases you need to do both
you can use these proguard rules for your GSON it should work:
GSON Proguard

Proguard Invalid class reference: android/support/v4/app/Fragment

I've been trying to get Proguard to work in this libgdx app of mine for hours, and I can't get past this error when I try running it:
Error:Execution failed for task
':android:transformClassesWithNewClassShrinkerForDebug'. >
com.android.build.gradle.shrinker.ClassLookupException: Invalid class
reference: android/support/v4/app/Fragment
I've tried adding a ton of different rules to proguard-rules.pro, nothing seems to work. Here are some of the rules I've tried:
dontwarn android.support.**
keep class android.support.v4.* { *; }
keep public class * extends android.support.v4.
keep public class * extends android.app.Fragment
dontwarn **CompatHoneycomb
keep class android.support.v4.** { *; }
optimizationpasses 5
keepattributes SourceFile,LineNumberTable
keep class android.support.** { *; }
Here's what my buildTypes look like in my Android build.gradle
buildTypes {
debug {
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
Edit
This is definitely a LibGDX problem, I tried it with a blank LibGDX project and I get the exact same error.

Android Proguard have some trouble with AVG Antivirus

I made an android app that always worked fine. Suddenly, the AVG Antivirus reported that my app is a malware. After a couple hours, I found the issue:
In the build.gradle, if I use the config below to generate signed APK, AVG reports (the APK) as malware:
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
But if I comment the last line, no threat is found:
buildTypes {
release {
shrinkResources true
minifyEnabled true
//proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
My proguard-rules.pro has nothing special:
-keepattributes Signature
-keepattributes *Annotation*
-keepattributes EnclosingMethod
-keep class io.codetail.animation.arcanimator.** { *; }
-keep class com.example.viewholders.** {
*;
}
-keep class com.android.vending.billing.**
-keep class cn.pedant.SweetAlert.Rotate3dAnimation {
public <init>(...);
}
-keepclassmembers class com.example.models.** {
*;
}
I'm using Android Studio 2.2.2 and my project uses Firebase. The AVG Antivirus version that I have in my android device is 5.9.0.1.224656.
The "malware" identified by AVG is Android/gp oi bccfdd.
Is there something that I can do to solve this problem?
Finally I got a solution. Just to change this line:
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
With this:
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
According to Android Studio User Guide:
"Tip: For even more code shrinking, try the proguard-android-optimize.txt file that's in the same location. It includes the same ProGuard rules, but with other optimizations that perform analysis at the bytecode level—inside and across methods—to reduce your APK size further and help it run faster."
Unfortunately, as I realized, this can cause false detections of malware by antivirus.

Proguard not minifying when debuggable set to true

I am trying to test my app which has passed the 64K limit.
I have set minify on but it doesn't work when debuggable is enabled. However, if I build a version with debuggable off then it shrinks it by 2/3!
Am I missing something? This is the relevant part of my Gradle file:
buildTypes {
release {
minifyEnabled true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
proguard-rules.pro:
-keep class .R
-keep class **.R$* {
<fields>;
}
-keepattributes *Annotation*
-keepclassmembers class ** {
#org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
<init>(java.lang.Throwable);
}
-dontwarn com.google.**
-dontwarn com.squareup.picasso.**
-dontnote com.google.**
-dontnote com.squareup.picasso.**
With proguard enabled your code gets obfuscated and debugging will not be possible. That is why when you want to debug and set the flag true, proguard does not activate and that is why you do not see the minification of your apk.
Check this post. It has a similar question and will help you understand the conditions better.

Errors while signing apk with proguard

I am trying to generate a signed apk with proguard ON. I have the following line the build.gradle for the proguard
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
But while generating the signed apk, I get the following error
Error:Execution failed for task ':app:packageRelease'.
> Unable to compute hash of D:\project_name\app\build\intermediates\classes-proguard\release\classes.jar
The app builds fine but the issue is only while signing the apk.
Add this line into build.gradle file
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
And add below line into the 'proguard-project.txt'
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
For more details go to the below links Link

Categories

Resources