Skip to content

Commit 1672930

Browse files
authored
Enable AGP newDsl (#9269)
Enable AGP newDsl - Rename to androidHostTest and include resources - avoid running robolectric on JDK < 17 - Avoid connectedReleaseAndroidTest for now
1 parent bb420b2 commit 1672930

11 files changed

Lines changed: 52 additions & 65 deletions

File tree

.github/workflows/build.yml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -563,26 +563,19 @@ jobs:
563563
env:
564564
API_LEVEL: ${{ matrix.api-level }}
565565

566-
- name: Run Release Tests
567-
uses: reactivecircus/android-emulator-runner@v2
568-
with:
569-
api-level: ${{ matrix.api-level }}
570-
arch: ${{ matrix.api-level == '34' && 'x86_64' || 'x86' }}
571-
script: ./gradlew :android-test-app:connectedCheck
572-
env:
573-
API_LEVEL: ${{ matrix.api-level }}
574-
575566
- name: Build Release App
576567
run: ./gradlew android-test-app:lint android-test-app:assembleRelease
577568

578-
- name: Run Release Tests
579-
uses: reactivecircus/android-emulator-runner@v2
580-
with:
581-
api-level: ${{ matrix.api-level }}
582-
arch: ${{ matrix.api-level == '34' && 'x86_64' || 'x86' }}
583-
script: ./gradlew :android-test-app:connectedReleaseAndroidTest
584-
env:
585-
API_LEVEL: ${{ matrix.api-level }}
569+
# Can't run with AGP 9
570+
# java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/tracing/Trace;
571+
# - name: Run Release Tests
572+
# uses: reactivecircus/android-emulator-runner@v2
573+
# with:
574+
# api-level: ${{ matrix.api-level }}
575+
# arch: ${{ matrix.api-level == '34' && 'x86_64' || 'x86' }}
576+
# script: ./gradlew :android-test-app:connectedReleaseAndroidTest
577+
# env:
578+
# API_LEVEL: ${{ matrix.api-level }}
586579

587580
testloom:
588581
runs-on: ubuntu-latest
File renamed without changes.

android-test/src/androidTest/java/okhttp/android/test/OkHttpTest.kt renamed to android-test/src/androidDeviceTest/java/okhttp/android/test/OkHttpTest.kt

File renamed without changes.

android-test/src/androidTest/java/okhttp/android/test/SingleAndroidTest.kt renamed to android-test/src/androidDeviceTest/java/okhttp/android/test/SingleAndroidTest.kt

File renamed without changes.

android-test/src/androidTest/java/okhttp/android/test/StrictModeTest.kt renamed to android-test/src/androidDeviceTest/java/okhttp/android/test/StrictModeTest.kt

File renamed without changes.

android-test/src/androidTest/java/okhttp/android/test/alpn/AlpnOverrideTest.kt renamed to android-test/src/androidDeviceTest/java/okhttp/android/test/alpn/AlpnOverrideTest.kt

File renamed without changes.

android-test/src/androidTest/java/okhttp/android/test/letsencrypt/LetsEncryptClientTest.kt renamed to android-test/src/androidDeviceTest/java/okhttp/android/test/letsencrypt/LetsEncryptClientTest.kt

File renamed without changes.

android-test/src/androidTest/java/okhttp/android/test/sni/SniOverrideTest.kt renamed to android-test/src/androidDeviceTest/java/okhttp/android/test/sni/SniOverrideTest.kt

File renamed without changes.

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ okhttpDokka=false
1313

1414
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
1515

16-
# AGP 9.0 Workarounds
17-
android.builtInKotlin=false
18-
android.newDsl=false
16+
# AGP 9.0 Settings
17+
android.builtInKotlin=true
18+
android.newDsl=true

okhttp/build.gradle.kts

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
import com.vanniktech.maven.publish.JavadocJar
44
import com.vanniktech.maven.publish.KotlinMultiplatform
5-
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
65
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
76
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
87
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSniffer
98
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension
109

1110
plugins {
1211
kotlin("multiplatform")
13-
id("com.android.library")
12+
id("com.android.kotlin.multiplatform.library")
1413
kotlin("plugin.serialization")
1514
id("com.vanniktech.maven.publish.base")
1615
id("binary-compatibility-validator")
@@ -54,9 +53,32 @@ kotlin {
5453
jvm {
5554
}
5655

57-
androidTarget {
58-
compilerOptions {
59-
jvmTarget.set(JvmTarget.JVM_17)
56+
androidLibrary {
57+
namespace = "okhttp.okhttp3"
58+
compileSdk = 35
59+
minSdk = 21
60+
61+
androidResources {
62+
enable = true
63+
}
64+
65+
optimization {
66+
consumerKeepRules.publish = true
67+
consumerKeepRules.files.add(file("okhttp3.pro"))
68+
}
69+
70+
withDeviceTest {
71+
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
72+
execution = "HOST"
73+
}
74+
75+
// SDK 35 needs 17, for now avoid trying to run on
76+
// multiple robolectric versions, since device tests
77+
// do that
78+
if (testJavaVersion >= 17) {
79+
withHostTest {
80+
isIncludeAndroidResources = true
81+
}
6082
}
6183
}
6284

@@ -157,17 +179,19 @@ kotlin {
157179
}
158180
}
159181

160-
val androidUnitTest by getting {
161-
dependencies {
162-
implementation(libs.assertk)
163-
implementation(libs.kotlin.test.annotations)
164-
implementation(libs.kotlin.test.common)
165-
implementation(libs.androidx.junit)
182+
if (testJavaVersion >= 17) {
183+
val androidHostTest by getting {
184+
dependencies {
185+
implementation(libs.assertk)
186+
implementation(libs.kotlin.test.annotations)
187+
implementation(libs.kotlin.test.common)
188+
implementation(libs.androidx.junit)
166189

167-
implementation(libs.junit.jupiter.engine)
168-
implementation(libs.junit.vintage.engine)
190+
implementation(libs.junit.jupiter.engine)
191+
implementation(libs.junit.vintage.engine)
169192

170-
implementation(libs.robolectric)
193+
implementation(libs.robolectric)
194+
}
171195
}
172196
}
173197
}
@@ -186,30 +210,7 @@ if (platform == "jdk8alpn") {
186210
}
187211
}
188212

189-
android {
190-
compileSdk = 35
191213

192-
namespace = "okhttp.okhttp3"
193-
194-
defaultConfig {
195-
minSdk = 21
196-
197-
consumerProguardFiles("okhttp3.pro")
198-
}
199-
200-
testOptions {
201-
unitTests {
202-
isIncludeAndroidResources = true
203-
}
204-
}
205-
206-
sourceSets {
207-
named("main") {
208-
manifest.srcFile("src/androidMain/AndroidManifest.xml")
209-
assets.srcDir("src/androidMain/assets")
210-
}
211-
}
212-
}
213214

214215
// From https://github.com/Kotlin/kotlinx-atomicfu/blob/master/atomicfu/build.gradle.kts
215216
val compileJavaModuleInfo by tasks.registering(JavaCompile::class) {
@@ -346,13 +347,6 @@ afterEvaluate {
346347
// https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/factory/AndroidUnitTest.java;l=339
347348
allJvmArgs = allJvmArgs.filter { !it.startsWith("--add-opens") }
348349
}
349-
if (name.matches("test.*UnitTest".toRegex()) && javaLauncher.get().metadata.languageVersion.asInt() < 17) {
350-
// Work around robolectric requirements and limitations
351-
// https://github.com/robolectric/robolectric/issues/10419
352-
filter {
353-
excludeTest("okhttp3.internal.publicsuffix.PublicSuffixDatabaseTest", null)
354-
}
355-
}
356350
}
357351
}
358352

@@ -368,5 +362,5 @@ tasks.withType<KotlinCompile> {
368362
apply(plugin = "io.github.usefulness.maven-sympathy")
369363

370364
mavenPublishing {
371-
configure(KotlinMultiplatform(javadocJar = JavadocJar.Empty(), androidVariantsToPublish = listOf("release")))
365+
configure(KotlinMultiplatform(javadocJar = JavadocJar.Empty()))
372366
}

0 commit comments

Comments
 (0)