Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkgs/ok_http/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## 0.1.1-wip
Comment thread
EchoEllet marked this conversation as resolved.

- Fix Android release mode crash due to missing OkHttp classes by explicitly keeping the classes that are consumed.
- `OkHttpClient` now receives an `OkHttpClientConfiguration` to configure the client on a per-call basis.
- `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`.
- Upgrade to `jni` 0.14.0
- Upgrade to `jnigen` 0.14.0
- Upgrade to `jni` 1.0.0
- Upgrade to `jnigen` 0.16.0
- `OKHttpClient` supports client certificates.
- Support `package:web_socket` 1.0.0.
- Set `minSdk=24`.
Expand Down
1 change: 1 addition & 0 deletions pkgs/ok_http/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ android {

defaultConfig {
minSdk = 24
consumerProguardFiles("proguard.txt")
}
}

Expand Down
35 changes: 35 additions & 0 deletions pkgs/ok_http/android/proguard.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# IMPORTANT: Keep this file in sync with the OkHttp classes
# declared in jnigen.yaml. JNI loads these classes by name,
# so they must not be removed in Android release builds.

-keep class okhttp3.Request** { *; }
-keep class okhttp3.RequestBody { *; }
-keep class okhttp3.Response { *; }
-keep class okhttp3.ResponseBody { *; }
-keep class okhttp3.OkHttpClient** { *; }
-keep class okhttp3.Call { *; }
-keep class okhttp3.Headers { *; }
-keep class okhttp3.Callback { *; }
-keep class okhttp3.ConnectionPool { *; }
-keep class okhttp3.Dispatcher { *; }
-keep class okhttp3.Cache { *; }
-keep class okhttp3.WebSocket { *; }

-keep class okio.ByteString { *; }

-keep class com.example.ok_http.RedirectReceivedCallback { *; }
-keep class com.example.ok_http.AsyncInputStreamReader { *; }
-keep class com.example.ok_http.DataCallback { *; }
-keep class com.example.ok_http.WebSocketInterceptor** { *; }
-keep class com.example.ok_http.WebSocketListenerProxy** { *; }
-keep class com.example.ok_http.FixedResponseX509ExtendedKeyManager { *; }

-keepclassmembers class com.example.ok_http.RedirectInterceptor {
public static com.example.ok_http.RedirectInterceptor$Companion Companion;
}

-keepclassmembers class com.example.ok_http.WebSocketInterceptor {
public static com.example.ok_http.WebSocketInterceptor$Companion Companion;
}

-keep class com.example.ok_http.RedirectInterceptor** { *; }
2 changes: 2 additions & 0 deletions pkgs/ok_http/example/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ GeneratedPluginRegistrant.java
key.properties
**/*.keystore
**/*.jks

.kotlin
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="ok_http_example"
android:name="${applicationName}"
Expand Down
4 changes: 4 additions & 0 deletions pkgs/ok_http/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
org.gradle.jvmargs=-Xmx4G -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
# This builtInKotlin flag was added automatically by Flutter migrator
android.builtInKotlin=false
# This newDsl flag was added automatically by Flutter migrator
android.newDsl=false
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
2 changes: 1 addition & 1 deletion pkgs/ok_http/example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.2.1" apply false
id "com.android.application" version "8.6.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}

Expand Down
11 changes: 3 additions & 8 deletions pkgs/ok_http/example/integration_test/certificate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import 'dart:typed_data';
import 'package:flutter/services.dart' show rootBundle;
import 'package:http/http.dart';
import 'package:integration_test/integration_test.dart';
import 'package:jni/jni.dart' show JStringExtension;
import 'package:ok_http/ok_http.dart';
import 'package:ok_http/src/jni/bindings.dart' as bindings;

import 'package:test/test.dart';

Future<Uint8List> loadCertificateBytes(String path) async {
Expand All @@ -28,14 +28,9 @@ void main() async {
await loadCertificateBytes('test_certs/test-combined.p12');
final (key, chain) =
loadPrivateKeyAndCertificateChainFromPKCS12(certBytes, '1234');
expect(
key
.as(bindings.Key.type)
.getFormat()!
.toDartString(releaseOriginal: true),
'PKCS#8');
expect(key.getFormat()!.toDartString(releaseOriginal: true), 'PKCS#8');
expect(chain.length, 1);
expect(chain[0].getType()!.toDartString(), 'X.509');
expect(chain[0].type$1!.toDartString(), 'X.509');
});

test('no key', () async {
Expand Down
1 change: 1 addition & 0 deletions pkgs/ok_http/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dev_dependencies:
http_profile: ^0.1.0
integration_test:
sdk: flutter
jni: ^1.0.0 # Used in integration tests.
test: ^1.23.1
web_socket_conformance_tests:
path: ../../web_socket_conformance_tests/
Expand Down
3 changes: 3 additions & 0 deletions pkgs/ok_http/jnigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ android_sdk_config:
add_gradle_deps: true
android_example: "example/"

# IMPORTANT: OkHttp classes declared here
# must be kept in sync with android/proguard.txt
# to support Android release builds.
classes:
- "okhttp3.Request"
- "okhttp3.RequestBody"
Expand Down
Loading