Skip to content

Commit

Permalink
Add test for dexing patch
Browse files Browse the repository at this point in the history
  • Loading branch information
dellisd committed Jul 25, 2023
1 parent 3737ced commit ba37023
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 2 deletions.
3 changes: 2 additions & 1 deletion gradle-plugin/src/test/fixtures/buildscript.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ project.buildscript.repositories {
}

project.buildscript.dependencies {
classpath 'app.cash.better.dynamic.features:app.cash.better.dynamic.features.gradle.plugin:+'
classpath 'app.cash.better.dynamic.features:agp-patch:+'
classpath 'app.cash.better.dynamic.features:gradle-plugin:+'
classpath libs.kotlin.gradle
classpath libs.agp
classpath "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:${libs.versions.ksp.get()}"
Expand Down
22 changes: 22 additions & 0 deletions gradle-plugin/src/test/fixtures/missing-dex/base/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'com.google.devtools.ksp'
apply plugin: 'app.cash.better.dynamic.features'
apply plugin: 'app.cash.better.dynamic.features.agp-patch'

android {
namespace "app.cash.better.dynamic.features.integration"

compileSdk 32
defaultConfig {
minSdk = 24

versionCode 1
}

dynamicFeatures = [':feature']
}

dependencies {
implementation "com.squareup.okhttp3:okhttp:4.9.3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest />
13 changes: 13 additions & 0 deletions gradle-plugin/src/test/fixtures/missing-dex/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
buildscript {
apply from: "${projectDir.absolutePath}/../buildscript.gradle"
}

allprojects {
repositories {
maven {
url "file://${rootDir}/../../../../build/localMaven"
}
mavenCentral()
google()
}
}
18 changes: 18 additions & 0 deletions gradle-plugin/src/test/fixtures/missing-dex/feature/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apply plugin: 'com.android.dynamic-feature'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'com.google.devtools.ksp'
apply plugin: 'app.cash.better.dynamic.features'

android {
namespace "app.cash.better.dynamic.features.integration.feature"

compileSdk 32
defaultConfig {
minSdk = 24
}
}

dependencies {
implementation project(":base")
implementation project(":library")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:dist="http://schemas.android.com/apk/distribution">
<dist:module
dist:instant="false"
dist:title="Feature">
<dist:delivery>
<dist:install-time />
</dist:delivery>
<dist:fusing dist:include="true" />
</dist:module>
</manifest>
2 changes: 2 additions & 0 deletions gradle-plugin/src/test/fixtures/missing-dex/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g
android.useAndroidX=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apply plugin: 'org.jetbrains.kotlin.jvm'

dependencies {
implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example;

public class JavaClass {
public String message() {
return "Java!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example

class KotlinClass {
fun message() = "Kotlin!"
}
5 changes: 5 additions & 0 deletions gradle-plugin/src/test/fixtures/missing-dex/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apply from: "../settings.gradle"

include ':base'
include ':feature'
include ':library'
3 changes: 2 additions & 1 deletion gradle-plugin/src/test/fixtures/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ dependencyResolutionManagement {

includeBuild('../../../../../') {
dependencySubstitution {
substitute module("app.cash.better.dynamic.features:app.cash.better.dynamic.features.gradle.plugin") using project(":gradle-plugin")
substitute module("app.cash.better.dynamic.features:gradle-plugin") using project(":gradle-plugin")
substitute module("app.cash.better.dynamic.features:agp-patch") using project(":agp-patch")
substitute module('app.cash.better.dynamic.features:codegen') using project(':codegen')
substitute module('app.cash.better.dynamic.features:codegen-api') using project(':codegen:api')
substitute module('app.cash.better.dynamic.features:codegen-ksp') using project(':codegen:ksp')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package app.cash.better.dynamic.features

import app.cash.better.dynamic.features.tasks.Version
import app.cash.better.dynamic.features.utils.assertThat
import com.google.common.truth.Truth.assertThat
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Test
import java.io.File
import kotlin.io.path.bufferedReader

class BetterDynamicFeaturesPluginTest {
@Test fun `base and feature apks have different library versions`() {
Expand Down Expand Up @@ -829,6 +831,28 @@ class BetterDynamicFeaturesPluginTest {
assertThat(high).isGreaterThan(low)
}

@Test fun `missing dex patch works correctly`() {
val integrationRoot = File("src/test/fixtures/missing-dex")

val gradleRunner = GradleRunner.create()
.withCommonConfiguration(integrationRoot)
.withArguments(":base:packageDebugUniversalApk", "--stacktrace")

gradleRunner.build()

val dexContent = dexdump(integrationRoot.resolve("base/build/outputs/apk_from_bundle/debug/base-debug-universal.apk"))
assertThat(dexContent.bufferedReader().lineSequence()).containsInConsecutiveOrder(
""" Class descriptor : 'Lcom/example/JavaClass;'""",
""" Access flags : 0x0001 (PUBLIC)""",
""" Superclass : 'Ljava/lang/Object;'""",
)
assertThat(dexContent.bufferedReader().lineSequence()).containsInConsecutiveOrder(
""" Class descriptor : 'Lcom/example/KotlinClass;'""",
""" Access flags : 0x0011 (PUBLIC FINAL)""",
""" Superclass : 'Ljava/lang/Object;'""",
)
}

private fun clearLockfile(root: File) {
root.lockfile().takeIf { it.exists() }?.delete()
}
Expand Down

0 comments on commit ba37023

Please sign in to comment.