Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android project won't work when compiled by Android Studio 4.0.1

This is a long story and I'm going try to provide as much details as I can.

I have been using android studio 3.x.x to built my apps over several months, until recently it started to offer me an update to the newest stable 4.0.1.

I updated and it was hassle free as it was supposed to be, all plugins updated without error and the code compiled at first in the new android studio, the project worked fine in tests then i uploaded to the play store's internal test track (here the problem starts).

the app started showing a some sort of lock or infinite loop error in some devices... it was weird because the very same devices when running the debug build were fine, at this moment i thought that some proguard rules are the problem. So I adjusted the build.grade file in order to the debug build have the same settings as the release build (shrink and minify TRUE).

after compiled the app runs smoothly in the emulator and in the problematic devices...
once more i uploaded it to google play, and downloaded from there the app doesn't work...

I made a very exhaustive and annoying code debug in order to get what method was being locked somehow and i found this suspect:

OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
    httpClientBuilder.readTimeout(15000, TimeUnit.MILLISECONDS);
    httpClientBuilder.writeTimeout(15000, TimeUnit.MILLISECONDS);
    httpClientBuilder.connectTimeout(15000, TimeUnit.MILLISECONDS);
    httpClientBuilder.retryOnConnectionFailure(true);
    httpClientBuilder.followRedirects(true);
    httpClientBuilder.followSslRedirects(true);
    httpClientBuilder.connectionPool(DEFAULT_CONNECTION_POOL);
    Dispatcher dispatcher = new Dispatcher();
    dispatcher.setMaxRequests(10);
    dispatcher.setMaxRequestsPerHost(10);
    httpClientBuilder.dispatcher(dispatcher);
    okHttpClient = httpClientBuilder.build();

private boolean isInternetOK(){
    boolean ret = false;
    try {
        okHttpClient.newCall(new Request.Builder().get().url("https://www.google.com").build()).execute();
        ret true;
    } catch (Exception e) {                
    }
    return ret;
}

In my launcher activity, before start login I verify if users internet connection is ok that is a simple code and the httpclient has a timeout of 15 seconds so would connect or fail fast.

it made no sense to me why this specific method is working in dev and not working when served from play store (in the very same device and very same build config)

I spend a few hours trying to solve the problem... until i decided to downgrade android studio to the previous version i was using. AND THE PROBLEM SOLVED BY ITSELF!

So i'm 100% sure the problem is related to android studio 4.0.1 and its gradle plugin and how they interact with "com.squareup.okhttp3:okhttp:3.12.12"

here comes the observations i made:

1- the apk generated by android studio 4.0.1 is 4.18MB while 3.6.3 generates a 4.33MB apk (same build.config and same proguard.rules)

2- after update android studio to 4.0.1 proguard.rules started showing lots of erros, like is said here: Unresolved class name proguard-rules Android Studio 4.0 but still compiles fine (and worked fine in debug with shrink and minify on)

3- the only difference in the project is android studio version and com.android.tools.build:gradle dependency, because it must follow android studio version.

Well this is as far as I got, i'm available to provide any more info and even the apks compiled from the different versions if anyone can help me... now i need to sleep because is 23h30 today is Saturday and i lost 7 hours of my life in this junk update

like image 851
Rafael Lima Avatar asked Aug 16 '20 02:08

Rafael Lima


1 Answers

it may be helpful for you to check internet, if your method not working on some devices

you can also get confirmation about your error it is due to check internet or any other

boolean hasActiveInternetConnection() {
    try {
        InetAddress ipAddr = InetAddress.getByName("google.com");
        return !ipAddr.equals("");
    } catch (Exception e) {
        return false;
    }
}
like image 159
Abdur Rehman Avatar answered Nov 04 '22 19:11

Abdur Rehman