Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility issues in latest version (from v2.0.3 to v2.0.6) #74

Closed
rafaco opened this issue Mar 10, 2020 · 7 comments
Closed

Compatibility issues in latest version (from v2.0.3 to v2.0.6) #74

rafaco opened this issue Mar 10, 2020 · 7 comments

Comments

@rafaco
Copy link

rafaco commented Mar 10, 2020

Latest versions cause a startup crash when using Android R build tools (preview). They also have considerably increase the minimum Android API required to use Pandora to API 21 but the minSdkVersion flag of this library still allowing API 14.

Android R problem:

  1. Update Android Studio to latest version (3.6.1).
  2. Create a new app project targeting Android R, it will automatically have:
android {
    compileSdkVersion 'android-R'
    buildToolsVersion "29.0.3"
    defaultConfig {
        minSdkVersion 'R'
        targetSdkVersion 'R'
    }
}
  1. Add jitpack and dependencies to the latest Pandora versions (v2.0.6)
  2. App builds but crash on initialisation with different outputs per versions

Pandora v2.0.6: FATAL EXCEPTION: java.lang.ExceptionInInitializerError at okhttp3.OkHttpClient.(OkHttpClient.kt:211)...

Pandora v2.0.3, v2.0.4 and v2.0.5: FATAL EXCEPTION: java.lang.NoSuchMethodError: No static method metafactory(...)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (...) at okhttp3.internal.Util.(Util.java:87)...

Pandora v2.0.2: Ok!

API<21 problem

Apps also crash if using latest versions in devices with API between 14 and 20:

Pandora v2.0.3, v2.0.4, v2.0.5 and v2.0.6: FATAL EXCEPTION: java.lang.ExceptionInInitializerError at okhttp3.OkHttpClient.(OkHttpClient.kt:211)... Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 19.

Cause

I believe all this issues are caused by the upgrade to Okhttp to v4.0.1 performed in Pandora v2.0.3.

Temporarily solution

We have downgrade Pandora to v2.0.2 and Retrofit to v2.3.0 (both using OkHttp 3.9.0). We can now run our app without problem from API 14 to latest API R (both included).

@whataa
Copy link
Owner

whataa commented Mar 13, 2020

The problems do exist.

OKHttpUrlConnection was introduced to implement log interception for Android's UrlConnection, but the library has been abandoned for a long time. The related APIs have been severely disconnected with the update of OKHttp, it is really incompatible, and the issue caused is greater than Proceeds, so I decided to remove it from Pandora.

This change became effective in version 2.1.0

After that, pandora no longer depends on the specific version number of OKHttp, and is fully compatible.

@whataa
Copy link
Owner

whataa commented Mar 13, 2020

#69

@rafaco
Copy link
Author

rafaco commented Mar 17, 2020

It sound like the right approach. Cheers!

I think you also introduced Java 8 requirement around the same time. Just in case you add it for OKHttpUrlConnection and you find it easy to remove to support more legacy apps.

@rafaco
Copy link
Author

rafaco commented Mar 18, 2020

First of all, congratulation for your new plugin, it works like a charm and I love it. I didn't know about this kind of build time injection/reflection and I will definitively investigate your implementation to learn from it. Thanks!

I have tested v2.1.0 and I can confirm that Android R problem is fixed.

Api<21 problem still the same as it's a requirement of OkHttp 4 which still in use. It's a runtime exception on okHttp initialisation and it happen even if you don't have Pandora plugin installed or even if the host app don't use okHttp/retrofit.

Easier fix will be changing minSdkVersion to 21 but it will reduce Pandora compatibility. I would rather downgrade to OkHttp 3, but if you don't want it you could try a runtime fix selectively for lower platform levels. I mean something like preventing okHttp initialisation when running on API<21. It will allow the app to be started with others Pandora goodies but it will probably also stop any communications with backend servers if the host app rely on Retrofit/OkHttp or even a new crash when calling Retrofit Builder from the host app.

@whataa
Copy link
Owner

whataa commented Mar 19, 2020

Thanks! As the OkHttp's README says:

  • OkHttp 4.x works on Android 5.0+ (API level 21+) and Java 8+.
  • OkHttp 3.12.x works on Android 2.3+ (API level 9+) and Java 7+.

For minSdkVersion < 21, the project should choose using OkHttp 3.12.x. But since Pandora introduced version 4, you need to exclude it and implementation OkHttp 3.12.x manually:

implementation ("com.github.whataa:pandora:v2.1.0") {
    exclude group: 'com.squareup.okhttp3'
    // or using: transitive false
}
implementation("com.squareup.okhttp3:okhttp:3.12.x")

the APIs Pandora used are included in every OkHttp version. That is, Pandora is independent of the specific version of OkHttp.

@rafaco
Copy link
Author

rafaco commented Mar 23, 2020

Thank you, this solve completely this issue for me.

In order to help others wanting to support API<21 in modern projects, the higher valid versions are:

  • OKHTTP_VERSION = "3.12.10"
  • RETROFIT_VERSION = "2.6.4"

But if your projects havesourceCompatibility JavaVersion.VERSION_1_7, previous versions produce tons of warning on build time while performing transformClassesWithPandora and pandora interceptor will not work on runtime despite a success build. They are all AGPBI warnings related to desugaring Retrofit Kotlin methods with R8. To solve this you can downgrade a bit more to following versions:
- OKHTTP_VERSION = "3.8.0"
- RETROFIT_VERSION = "2.3.0"

@rafaco rafaco closed this as completed Mar 23, 2020
@rafaco
Copy link
Author

rafaco commented Mar 24, 2020

I think you also introduced Java 8 requirement around the same time. Just in case you add it for OKHttpUrlConnection and you find it easy to remove to support more legacy apps.

Yes, I can confirm it now, Pandora works again in Java 7 projects when excluding OkHttp 4.x and replacing it by 3.12.10, as Java 8+ requirement came from OkHttp 4.x. Nice one!

My previous comment has wrong info and I will edit it. I was having issues because pandora-noop has okhttp dependency also and I forget to exclude/replace OkHttp there...

@whataa: Do you think Pandora.getInterceptor() still useful after the plugin release? Removing this method from your public interface will allow to remove OkHttp dependency as well from your noop artifact improving the impact on release builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants