Skip to content

Commit 3ae907d

Browse files
committed
fix(ok_http): android release mode crash dart-lang#1950
1 parent a75d34a commit 3ae907d

5 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎pkgs/ok_http/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 0.1.1-wip
22

3+
- Fix Android release mode crash due to missing OkHttp classes by explicitly keeping the classes that are consumed.
34
- `OkHttpClient` now receives an `OkHttpClientConfiguration` to configure the client on a per-call basis.
45
- `OkHttpClient` supports setting four types of timeouts: [`connectTimeout`](https://square.github.io/okhttp/5.x/okhttp/okhttp3/-ok-http-client/-builder/connect-timeout.html), [`readTimeout`](https://square.github.io/okhttp/5.x/okhttp/okhttp3/-ok-http-client/-builder/read-timeout.html), [`writeTimeout`](https://square.github.io/okhttp/5.x/okhttp/okhttp3/-ok-http-client/-builder/write-timeout.html), and [`callTimeout`](https://square.github.io/okhttp/5.x/okhttp/okhttp3/-ok-http-client/-builder/call-timeout.html), using the `OkHttpClientConfiguration`.
56
- Upgrade to `jni` 1.0.0

‎pkgs/ok_http/android/build.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ android {
5757

5858
defaultConfig {
5959
minSdk = 24
60+
consumerProguardFiles("proguard.txt")
6061
}
6162
}
6263

‎pkgs/ok_http/android/proguard.txt‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# IMPORTANT: Keep this file in sync with the OkHttp classes
2+
# declared in jnigen.yaml. JNI loads these classes by name,
3+
# so they must not be removed in Android release builds.
4+
5+
-keep class okhttp3.Request** { *; }
6+
-keep class okhttp3.RequestBody { *; }
7+
-keep class okhttp3.Response { *; }
8+
-keep class okhttp3.ResponseBody { *; }
9+
-keep class okhttp3.OkHttpClient** { *; }
10+
-keep class okhttp3.Call { *; }
11+
-keep class okhttp3.Headers { *; }
12+
-keep class okhttp3.Callback { *; }
13+
-keep class okhttp3.ConnectionPool { *; }
14+
-keep class okhttp3.Dispatcher { *; }
15+
-keep class okhttp3.Cache { *; }
16+
-keep class okhttp3.WebSocket { *; }
17+
18+
-keep class okio.ByteString { *; }
19+
20+
-keep class com.example.ok_http.RedirectReceivedCallback { *; }
21+
-keep class com.example.ok_http.AsyncInputStreamReader { *; }
22+
-keep class com.example.ok_http.DataCallback { *; }
23+
-keep class com.example.ok_http.WebSocketInterceptor** { *; }
24+
-keep class com.example.ok_http.WebSocketListenerProxy** { *; }
25+
-keep class com.example.ok_http.FixedResponseX509ExtendedKeyManager { *; }
26+
27+
-keepclassmembers class com.example.ok_http.RedirectInterceptor {
28+
public static com.example.ok_http.RedirectInterceptor$Companion Companion;
29+
}
30+
31+
-keepclassmembers class com.example.ok_http.WebSocketInterceptor {
32+
public static com.example.ok_http.WebSocketInterceptor$Companion Companion;
33+
}
34+
35+
-keep class com.example.ok_http.RedirectInterceptor** { *; }

‎pkgs/ok_http/example/android/app/src/main/AndroidManifest.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<uses-permission android:name="android.permission.INTERNET"/>
23
<application
34
android:label="ok_http_example"
45
android:name="${applicationName}"

‎pkgs/ok_http/jnigen.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ android_sdk_config:
1212
add_gradle_deps: true
1313
android_example: "example/"
1414

15+
# IMPORTANT: OkHttp classes declared here
16+
# must be kept in sync with android/proguard.txt
17+
# to support Android release builds.
1518
classes:
1619
- "okhttp3.Request"
1720
- "okhttp3.RequestBody"

0 commit comments

Comments
 (0)