Skip to content

Commit 9af87fe

Browse files
authored
Use R8 optimization tool in Android modules (#4892)
A step back from this PR #4743 I created a smaller, clear PR with the R8 task only and without the separation of Debug and Release Install paths ## Motivation As part of Mill’s Android integration, we want to use the R8 optimization tool to create smaller dex files ![image](https://github.com/user-attachments/assets/9afaf36a-b986-4fc6-9397-2f906ff8fb66) ![image](https://github.com/user-attachments/assets/a6072464-4547-43b0-8946-9b82de70ff6f) ## Provided in this PR 1) Run the R8 task which will shrink the dex files according to the proguard rules
1 parent 916dfaa commit 9af87fe

File tree

22 files changed

+668
-4
lines changed

22 files changed

+668
-4
lines changed

example/androidlib/java/1-hello-world/build.mill

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ object app extends AndroidAppModule {
2424
def androidApplicationId = "com.helloworld.app"
2525
def androidApplicationNamespace = "com.helloworld.app"
2626

27-
// Configuration for ReleaseKey
27+
/**
28+
* Configuration for ReleaseKey
29+
* WARNING: Replace these default values with secure and private credentials before using in production.
30+
* Never use these defaults in a production environment as they are not secure.
31+
* This is just for testing purposes.
32+
*/
2833
def androidReleaseKeyName: T[Option[String]] = Task { Some("releaseKey.jks") }
2934
def androidReleaseKeyAlias: T[Option[String]] = Task { Some("releaseKey") }
3035
def androidReleaseKeyPass: T[Option[String]] = Task { Some("MillBuildTool") }

example/androidlib/java/2-app-bundle/build.mill

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ object bundle extends AndroidAppBundle {
1717
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)
1818
def androidCompileSdk = 35
1919

20+
/**
21+
* Configuration for ReleaseKey
22+
* WARNING: Replace these default values with secure and private credentials before using in production.
23+
* Never use these defaults in a production environment as they are not secure.
24+
* This is just for testing purposes.
25+
*/
2026
def androidApplicationId = "com.helloworld.app"
2127
def androidApplicationNamespace = "com.helloworld.app"
2228

example/androidlib/java/4-sum-lib-java/build.mill

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ object lib extends AndroidLibModule with PublishModule {
3838
developers = Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi"))
3939
)
4040

41-
// Configuration for ReleaseKey
41+
/**
42+
* Configuration for ReleaseKey
43+
* WARNING: Replace these default values with secure and private credentials before using in production.
44+
* Never use these defaults in a production environment as they are not secure.
45+
* This is just for testing purposes.
46+
*/
4247
def androidReleaseKeyAlias: T[Option[String]] = Task { Some("releaseKey") }
4348
def androidReleaseKeyPass: T[Option[String]] = Task { Some("MillBuildTool") }
4449
def androidReleaseKeyStorePass: T[Option[String]] = Task { Some("MillBuildTool") }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# override def proguardConfigs: T[Seq[PathRef]] in build.mill
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
-renamesourcefileattribute SourceFilex
22+
23+
-keep class com.helloworld.** { *; }
2.63 KB
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.helloworld.app;
2+
3+
import static org.junit.Assert.*;
4+
5+
import android.content.Context;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
import androidx.test.platform.app.InstrumentationRegistry;
8+
import com.helloworld.SampleLogic;
9+
import org.junit.Test;
10+
import org.junit.runner.RunWith;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
23+
assertEquals("com.helloworld.app", appContext.getPackageName());
24+
assertEquals(32.0f, SampleLogic.textSize(), 0.0001f);
25+
}
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.helloworld.app" android:versionCode="1" android:versionName="1.0">
2+
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="35"/>
3+
<application android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" android:debuggable="true">
4+
<activity android:name=".MainActivity"
5+
android:exported="true">
6+
<intent-filter>
7+
<action android:name="android.intent.action.MAIN"/>
8+
<category android:name="android.intent.category.LAUNCHER"/>
9+
</intent-filter>
10+
</activity>
11+
</application>
12+
<instrumentation
13+
android:name="androidx.test.runner.AndroidJUnitRunner"
14+
android:targetPackage="com.helloworld.app" />
15+
</manifest>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.helloworld;
2+
3+
public class SampleLogic {
4+
5+
public static float textSize() {
6+
return 32f;
7+
}
8+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.helloworld.app;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.view.Gravity;
6+
import android.view.ViewGroup.LayoutParams;
7+
import android.widget.TextView;
8+
9+
public class MainActivity extends Activity {
10+
@Override
11+
protected void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
14+
// Create a new TextView
15+
TextView textView = new TextView(this);
16+
17+
// Set the text to the string resource
18+
textView.setText(getString(R.string.hello_world));
19+
20+
// Set text size
21+
textView.setTextSize(32);
22+
23+
// Center the text within the view
24+
textView.setGravity(Gravity.CENTER);
25+
26+
// Set the layout parameters (width and height)
27+
textView.setLayoutParams(
28+
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
29+
30+
// Set the text color using a resource
31+
textView.setTextColor(getResources().getColor(R.color.text_green));
32+
33+
// Set the background color using a resource
34+
textView.setBackgroundColor(getResources().getColor(R.color.white));
35+
36+
// Set the content view to display the TextView
37+
setContentView(textView);
38+
}
39+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
<color name="white">#FFFFFF</color>
3+
<color name="text_green">#34A853</color>
4+
</resources>

0 commit comments

Comments
 (0)