-
-
Notifications
You must be signed in to change notification settings - Fork 407
Android/r8 optimization #4743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Android/r8 optimization #4743
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
0ae5f30
start the r8
irodotos7 e84044e
some progress
irodotos7 f99d737
finally a classes.dex
irodotos7 ade610a
finally a classes.dex
irodotos7 ab4b3fb
create the apk and install it works
irodotos7 b851b41
release and debug path
irodotos7 abb441b
release and debug path
irodotos7 d4c32a9
release and debug path
irodotos7 7d172cb
release and debug path
irodotos7 7d871d2
Merge branch 'main' into android/R8-optimization
irodotos7 cd795db
release and debug path
irodotos7 09a750d
release and debug path
irodotos7 541ae8b
release and debug path
irodotos7 886dd86
release and debug path
irodotos7 2504a5b
Merge branch 'main' into android/R8-optimization
irodotos7 efaef18
create the apk and install it works
irodotos7 207e3c0
finally a classes.dex
irodotos7 d0afef9
change ci action
irodotos7 9b8e0b3
change ci action
irodotos7 a557aba
change ci action
irodotos7 fbe9425
koltin release and debug install
irodotos7 82a2ef0
koltin release and debug install
irodotos7 3c1b4df
cleanup
irodotos7 91f0806
Merge branch 'main' into android/R8-optimization
irodotos7 419878f
cleanup
irodotos7 864ce35
cleanup
irodotos7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
-renamesourcefileattribute SourceFilex | ||
|
||
-keep class com.helloworld.** { *; } | ||
|
Binary file not shown.
26 changes: 26 additions & 0 deletions
26
...oid/javalib/5-R8/app/src/androidTest/java/com/helloworld/app/ExampleInstrumentedTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.helloworld.app; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import android.content.Context; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import com.helloworld.SampleLogic; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
assertEquals("com.helloworld.app", appContext.getPackageName()); | ||
assertEquals(32.0f, SampleLogic.textSize(), 0.0001f); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
example/android/javalib/5-R8/app/src/main/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.helloworld.app" android:versionCode="1" android:versionName="1.0"> | ||
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/> | ||
<application android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true"> | ||
<activity android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
<instrumentation | ||
android:name="androidx.test.runner.AndroidJUnitRunner" | ||
android:targetPackage="com.helloworld.app" /> | ||
</manifest> |
8 changes: 8 additions & 0 deletions
8
example/android/javalib/5-R8/app/src/main/java/com/helloworld/SampleLogic.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.helloworld; | ||
|
||
public class SampleLogic { | ||
|
||
public static float textSize() { | ||
return 32f; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
example/android/javalib/5-R8/app/src/main/java/com/helloworld/app/MainActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.helloworld.app; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.view.Gravity; | ||
import android.view.ViewGroup.LayoutParams; | ||
import android.widget.TextView; | ||
|
||
public class MainActivity extends Activity { | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
// Create a new TextView | ||
TextView textView = new TextView(this); | ||
|
||
// Set the text to the string resource | ||
textView.setText(getString(R.string.hello_world)); | ||
|
||
// Set text size | ||
textView.setTextSize(32); | ||
|
||
// Center the text within the view | ||
textView.setGravity(Gravity.CENTER); | ||
|
||
// Set the layout parameters (width and height) | ||
textView.setLayoutParams( | ||
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); | ||
|
||
// Set the text color using a resource | ||
textView.setTextColor(getResources().getColor(R.color.text_green)); | ||
|
||
// Set the background color using a resource | ||
textView.setBackgroundColor(getResources().getColor(R.color.white)); | ||
|
||
// Set the content view to display the TextView | ||
setContentView(textView); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
example/android/javalib/5-R8/app/src/main/res/values/colors.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<resources> | ||
<color name="white">#FFFFFF</color> | ||
<color name="text_green">#34A853</color> | ||
</resources> |
4 changes: 4 additions & 0 deletions
4
example/android/javalib/5-R8/app/src/main/res/values/strings.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<resources> | ||
<string name="app_name">HelloWorldApp</string> | ||
<string name="hello_world">Hello, World Java!</string> | ||
</resources> |
20 changes: 20 additions & 0 deletions
20
example/android/javalib/5-R8/app/src/test/java/com/helloworld/ExampleUnitTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.helloworld; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import com.helloworld.app.R; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
public class ExampleUnitTest { | ||
@Test | ||
public void textSize_isCorrect() { | ||
|
||
assertEquals(32f, SampleLogic.textSize(), 0.000001f); | ||
assertEquals(0x7f010000, R.color.text_green); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Proguard rules for instrumented tests | ||
|
||
# Suppress warnings (so that you aren’t spammed with messages for unused rules) | ||
-ignorewarnings | ||
|
||
# Do not run any code optimizations – we want to keep our test code unchanged. | ||
-dontoptimize | ||
|
||
# Keep all annotation metadata (needed for reflection-based test frameworks) | ||
-keepattributes *Annotation* | ||
|
||
# Keep all Espresso framework classes and specifically ensure that the idling resources aren’t stripped | ||
-keep class androidx.test.espresso.** { *; } | ||
-keep class androidx.test.espresso.IdlingRegistry { *; } | ||
-keep class androidx.test.espresso.IdlingResource { *; } | ||
|
||
# Suppress notes and warnings for older JUnit and Android test classes | ||
-dontnote junit.framework.** | ||
-dontnote junit.runner.** | ||
|
||
-dontwarn androidx.test.** | ||
-dontwarn org.junit.** | ||
-dontwarn org.hamcrest.** | ||
-dontwarn com.squareup.javawriter.JavaWriter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// This section sets up a basic Android project using Mill. | ||
// We utilize `AndroidAppModule` and `AndroidSdkModule` to streamline the process of | ||
// building an Android application with minimal configuration. | ||
// | ||
// By extending `AndroidAppModule`, we inherit all Android-related tasks such as | ||
// resource generation, APK building, DEX conversion, and APK signing. | ||
// Additionally, `AndroidSdkModule` is embedded, making SDK management seamless. | ||
|
||
//// SNIPPET:BUILD | ||
package build | ||
|
||
import mill._, javalib._ | ||
|
||
import mill.javalib.android.{AndroidAppModule, AndroidSdkModule} | ||
import mill.javalib.android.AndroidTestModule | ||
|
||
// Create and configure an Android SDK module to manage Android SDK paths and tools. | ||
object androidSdkModule0 extends AndroidSdkModule { | ||
def buildToolsVersion = "35.0.0" | ||
} | ||
|
||
// Actual android application | ||
object app extends AndroidAppModule { | ||
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0) | ||
def androidMinSdk = 19 | ||
def androidCompileSdk = 35 | ||
|
||
// Configuration for ReleaseKey | ||
def androidReleaseKeyName: T[Option[String]] = Task { Some("releaseKey.jks") } | ||
def androidReleaseKeyAlias: T[Option[String]] = Task { Some("releaseKey") } | ||
def androidReleaseKeyPass: T[Option[String]] = Task { Some("MillBuildTool") } | ||
def androidReleaseKeyStorePass: T[Option[String]] = Task { Some("MillBuildTool") } | ||
|
||
override def androidVirtualDeviceIdentifier: String = "java-test" | ||
|
||
object test extends AndroidAppTests with TestModule.Junit4 { | ||
def testFramework = "com.novocode.junit.JUnitFramework" | ||
def ivyDeps = super.ivyDeps() ++ Seq( | ||
ivy"junit:junit:4.13.2" | ||
) | ||
} | ||
|
||
object it extends AndroidAppInstrumentedTests with AndroidTestModule.AndroidJUnit { | ||
|
||
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0) | ||
|
||
override def instrumentationPackage = "com.helloworld.app" | ||
|
||
/* TODO currently the dependency resolution ignores the platform type and kotlinx-coroutines-core has | ||
* conflicting classes with kotlinx-coroutines-core-jvm . Remove the exclusions once the dependency | ||
* resolution resolves conflicts between androidJvm and jvm platform types | ||
*/ | ||
def ivyDeps = super.ivyDeps() ++ Seq( | ||
ivy"androidx.test.ext:junit:1.2.1".exclude(( | ||
"org.jetbrains.kotlinx", | ||
"kotlinx-coroutines-core-jvm" | ||
)), | ||
ivy"androidx.test:runner:1.6.2", | ||
ivy"androidx.test.espresso:espresso-core:3.5.1".exclude(( | ||
"org.jetbrains.kotlinx", | ||
"kotlinx-coroutines-core-jvm" | ||
)), | ||
ivy"junit:junit:4.13.2" | ||
) | ||
} | ||
|
||
} | ||
|
||
////SNIPPET:END | ||
|
||
/** Usage | ||
|
||
> ./mill show app.androidReleaseApk | ||
".../out/app/androidReleaseApk.dest/app.apk" | ||
|
||
> ./mill show app.androidDebugApk | ||
".../out/app/androidDebugApk.dest/app.apk" | ||
|
||
*/ | ||
|
||
// This command triggers the build process, which installs the Android Setup, compiles the Java | ||
// code, generates Android resources, converts Java bytecode to DEX format, packages everything | ||
// into an APK, optimizes the APK using `zipalign`, and finally signs it. | ||
// | ||
// This Mill build configuration is designed to build a simple "Hello World" Android application. | ||
// By extending `AndroidAppModule`, we leverage its predefined Android build tasks, ensuring that | ||
// all necessary steps (resource generation, APK creation, and signing) are executed automatically. | ||
// | ||
// #### Project Structure: | ||
// The project follows the standard Android app layout. Below is a typical project folder structure: | ||
// | ||
// ---- | ||
// . | ||
//├── app | ||
//│ └── src | ||
//│ ├── androidTest/java/com/helloworld/app/ExampleInstrumentedTest.java | ||
//│ ├── main | ||
//│ │ ├── AndroidManifest.xml | ||
//│ │ ├── java/com/helloworld/app/MainActivity.java | ||
//│ │ └── res | ||
//│ │ └── values | ||
//│ │ ├── colors.xml | ||
//│ │ └── strings.xml | ||
//│ └── test/java/com/helloworld/app/ExampleUnitTest.java | ||
//└── build.mill | ||
// ---- | ||
// | ||
|
||
/** Usage | ||
|
||
> ./mill show app.test | ||
...compiling 2 Java source... | ||
|
||
> cat out/app/test/testForked.dest/worker-0/out.json | ||
["",[{"fullyQualifiedName":"com.helloworld.ExampleUnitTest.textSize_isCorrect","selector":"com.helloworld.ExampleUnitTest.textSize_isCorrect","duration":...,"status":"Success"}]] | ||
|
||
*/ | ||
|
||
// This command runs unit tests on your local environment. | ||
|
||
/** Usage | ||
|
||
> ./mill show app.createAndroidVirtualDevice | ||
...Name: java-test, DeviceId: medium_phone... | ||
|
||
> ./mill show app.startAndroidEmulator | ||
|
||
> ./mill show app.androidReleaseInstall | ||
...All files should be loaded. Notifying the device... | ||
|
||
> ./mill show app.androidDebugInstall | ||
...All files should be loaded. Notifying the device... | ||
|
||
> ./mill show app.stopAndroidEmulator | ||
|
||
> ./mill show app.deleteAndroidVirtualDevice | ||
|
||
*/ | ||
|
||
// The android tests (existing typically in androidTest directory, aka instrumented tests) | ||
// typically run on an android device. | ||
// The createAndroidVirtualDevice command creates an AVD (Android Virtual Device) | ||
// and the startAndroidEmulator command starts the AVD. The it task runs the android tests | ||
// against the available AVD. The stopAndroidEmulator command stops the AVD and the | ||
// destroyAndroidVirtualDevice command destroys the AVD. | ||
// The provided commands can be used in a CI/CD pipeline assuming the right setup is in place. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.