I encountered some inexplicable bugs while using OkHttp Retrofit RxAndroid. As follows:

ArrayIndexOutOfBoundsException

> Throwing new exception 'length=6; The index = 7 'with unexpected pending exception: Java. Lang. ArrayIndexOutOfBoundsException: length = 6; index=6Copy the code

Solution: Uncheck Instant Run and recompile every time you Run it. But this feature has been deprecated since Android Studio3.5.

I tried this and it didn’t work, but it was caused by a mismatch between Retrofit, RxAndroid, and Adapter-RxJava versions. RxAndroid is 3.0, the original Adapter-RxJava used version 2.

The changed dependencies look like this

3.14 implementation ` ` ` / / okHttp 'com. Squareup. Okhttp3: okHttp: 3.14.9' / / Retrofit 2.9 implementation 'com. Squareup. Retrofit2: retrofit: 2.9.0' / / Convert Google Json (Convert the result to the Model) implementation 'com. Squareup. Retrofit2: converter - gson: 2.3.0' / / Retrofit CallAdapter convert to RxJava implementation 'com. Squareup. Retrofit2: adapter - rxjava3:2.9.0' / / RxAndroid 3.0 implementation 'IO. Reactivex. Rxjava3: RxAndroid: 3.0.0' ` ` `Copy the code

BootstrapMethodError

> Java. Lang. BootstrapMethodError: Exception from the call site # 1 the bootstrap method...Copy the code

Solution: This is because Retrofit uses new features in JDK8, Lamdba, etc., so we need to add support in our app build.gradle.

' '// Support new features of JDK1.8 compileOptions {sourceCompatibility JavUncomfortable.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } ```Copy the code

That should solve the problem. The above two problems are not easy to locate, post hope can be helpful, in short, or to be careful.