5

I have an application and now I'm going to release it. I've created an apk file, and installed it but when I send login request to the server, It returns null..

Weird thing is that when I launch my application with debug build, It works fine. The problem happens on release mode only. So I thought the problem is from proguard after reading this article

Here's what I've done so far.

  1. Added all proguard rules that is needed. (Retrofit, Okhttp3, Glide) - Not worked.
  2. Create an apk with [Build apk(s)] in Build menu and test it - Worked but it is debug.

Any help would be appreciated...

This is my build.gradle file.

defaultConfig {
    multiDexEnabled true       
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:design:$rootProject.supportLibraryVersion"
    implementation "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:gridlayout-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:animated-vector-drawable:$rootProject.supportLibraryVersion"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    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'       
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'     
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
    implementation 'com.squareup:otto:1.3.8'
    implementation 'com.github.nisrulz:recyclerviewhelper:26.0.0'
    implementation 'jp.wasabeef:recyclerview-animators:2.2.7'
    implementation 'com.github.ittianyu:BottomNavigationViewEx:1.2.4'
    implementation 'com.blankj:utilcode:1.9.6'
    implementation 'com.github.bumptech.glide:glide:4.3.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1'
    implementation 'com.j256.ormlite:ormlite-core:5.0'
    implementation 'com.j256.ormlite:ormlite-android:5.0'
    implementation 'io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:1.1.3'
    implementation 'com.akexorcist:RoundCornerProgressBar:2.0.3'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'
    implementation 'com.daimajia.easing:library:2.0@aar'
    implementation 'com.daimajia.androidanimations:library:2.3@aar'
    implementation files('libs/opencsv-3.8.jar')
    implementation('tk.zielony:carbon:0.15.0.1') {
        exclude group: 'com.android.support', module: 'animated-vector-drawable'
        exclude group: 'com.android.support', module: 'gridlayout-v7'
    }       
    implementation 'com.github.QuadFlask:colorpicker:0.0.13'
    implementation 'com.android.support:multidex:1.0.2'
    implementation 'com.fasterxml.jackson.core:jackson-core:2.7.3'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
    implementation 'com.liulishuo.filedownloader:library:1.6.9'
    implementation 'org.jsoup:jsoup:1.11.2'
    implementation project(':typekit')
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    compile('com.crashlytics.sdk.android:crashlytics:2.9.0@aar') {
        transitive = true;
    }
}

And here is my proguard-rules.pro file.

-dontwarn com.google.android.gms.common.GooglePlayServicesUtil

-ignorewarnings
-keep class * {
    public private *;
}    
# Retrofit   
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain service method parameters.
-keepclassmembernames,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement    
# OkHttp 3    
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
# A resource is loaded with a relative path so the package of this class must be preserved.    

# Glide

-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49
Tura
  • 1,227
  • 11
  • 22
  • are you pointing same URL for both debug and release mode ? – Hemant Parmar Feb 21 '18 at 07:04
  • 1
    disable proguard and generate a release build then try it. If it still not works then it might not be proguard issue – Arshad Feb 21 '18 at 07:06
  • its because you have missed some libs rules in pro-gaurd, you can go to Build Variants --> change the app to release then run the app and check the log, you will find the missing rules in your pro-gaurd – AbuQauod Feb 21 '18 at 07:06
  • Well I tried release build without proguard, still not worked. Anyway, I found my problem and fix it! – Tura Feb 21 '18 at 08:29
  • Which converter do you use along with Retrofit? Also, these lines look very bad to me: `-ignorewarnings`, `-keep class * { public private *; }` – Miha_x64 Feb 21 '18 at 08:38
  • @Miha_x64 use gson-converter with Retrofit. And.. I don't have any idea about that. It was generated by Android Studio. I only added rules about libraries. What it means? – Tura Feb 21 '18 at 08:51
  • What was generated by Android Studio? O_o For Gson, you need to keep field names in classes which you (de)serialize by means of `ReflectiveTypeAdapterFactory` (i. e. without writing your own type adapters). – Miha_x64 Feb 21 '18 at 10:12
  • What you said, `-ignorewarnings, -keep class * { public private *; }` this code was generated by Android Studio. And I'm not sure that I understand what you said about Gson. Could you post an answer or give a link for more detail? Should I keep VOs with Gson in `proguard-rules.pro`? – Tura Feb 22 '18 at 02:42

4 Answers4

3

I made a foolish mistake.

I missed one proguard rule. Which is Otto bus's.

-keepattributes *Annotation*
-keepclassmembers class ** {
    @com.squareup.otto.Subscribe public *;
    @com.squareup.otto.Produce public *;
}

I have searched only github. There's no section about proguard. I found it on Square's blog.

If your code seems to be effected by proguard, then check twice and search more!

Tura
  • 1,227
  • 11
  • 22
0

I added the below line in gradle.properties and it worked smoothly after that.

android.enableR8 = false
Waqar UlHaq
  • 6,144
  • 2
  • 34
  • 42
Piyushk19
  • 9
  • 1
0

My solution which is worked for me is, Just disable and enable the debug option button in developer setting.

0

I had an API whose data was necessary as a prerequisite before navigation from the Splash screen to other screens. This API endpoint was something like https://fakesite.com/pseudo-api/. The solution was removing the / at the end. For some reason https://fakesite.com/pseudo-api/ would not be accessible from the release versions but https://fakesite.com/pseudo-api would.

Manil Malla
  • 133
  • 8