Skip to content
Merged
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
7 changes: 6 additions & 1 deletion example/androidlib/java/1-hello-world/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ object app extends AndroidAppModule {
def androidApplicationId = "com.helloworld.app"
def androidApplicationNamespace = "com.helloworld.app"

// Configuration for ReleaseKey
/**
* Configuration for ReleaseKey
* WARNING: Replace these default values with secure and private credentials before using in production.
* Never use these defaults in a production environment as they are not secure.
* This is just for testing purposes.
*/
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") }
Expand Down
6 changes: 6 additions & 0 deletions example/androidlib/java/2-app-bundle/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ object bundle extends AndroidAppBundle {
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)
def androidCompileSdk = 35

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

Expand Down
7 changes: 6 additions & 1 deletion example/androidlib/java/4-sum-lib-java/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ object lib extends AndroidLibModule with PublishModule {
developers = Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi"))
)

// Configuration for ReleaseKey
/**
* Configuration for ReleaseKey
* WARNING: Replace these default values with secure and private credentials before using in production.
* Never use these defaults in a production environment as they are not secure.
* This is just for testing purposes.
*/
def androidReleaseKeyAlias: T[Option[String]] = Task { Some("releaseKey") }
def androidReleaseKeyPass: T[Option[String]] = Task { Some("MillBuildTool") }
def androidReleaseKeyStorePass: T[Option[String]] = Task { Some("MillBuildTool") }
Expand Down
23 changes: 23 additions & 0 deletions example/androidlib/java/5-R8/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# override def proguardConfigs: T[Seq[PathRef]] in build.mill
#
# 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 added example/androidlib/java/5-R8/app/releaseKey.jks
Binary file not shown.
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 example/androidlib/java/5-R8/app/src/main/AndroidManifest.xml
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>
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;
}
}
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);
}
}
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>
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>
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);
}
}
24 changes: 24 additions & 0 deletions example/androidlib/java/5-R8/app/test-proguard-rules.pro
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
104 changes: 104 additions & 0 deletions example/androidlib/java/5-R8/build.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// R8 is a code shrinker and obfuscator for Android applications. Is designed to optimize the size of the APK
// while maintaining the functionality of the app.
// When using R8, you can configure the rules for code shrinking and obfuscation in a ProGuard configuration file.
// R8 relies on ProGuard rules files to adjust its default behavior and gain a better understanding of your app’s structure,
// such as identifying the classes that act as entry points. While you can modify some of these rules files,
// certain rules may be automatically generated by compile-time tools (like AAPT2) or inherited from your app’s library dependencies.
// You need 2 files on the root of your project:
//
// * proguard-rules.pro: This file contains the rules for R8 to follow when shrinking and obfuscating the code.
//
// * test-proguard-rules.pro: This file contains the rules for R8 to follow when shrinking and obfuscating the unit and instrumented tests.
//
// You can also override the default Proguard files by using `override def proguardConfigs: T[Seq[PathRef]]`
// More informations about the R8 in general and about the Proguard rules files can be found in the links below:
//
// https://developer.android.com/build/shrink-code
//
// https://www.guardsquare.com/manual/configuration/usage
package build

import mill._, androidlib._, scalalib._

object androidSdkModule0 extends AndroidSdkModule { // <1>
def buildToolsVersion = "35.0.0"
}

object app extends AndroidAppModule { // <2>
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)
def androidMinSdk = 19
def androidCompileSdk = 35
def androidApplicationId = "com.helloworld.app"
def androidApplicationNamespace = "com.helloworld.app"

/**
* Configuration for ReleaseKey
* WARNING: Replace these default values with secure and private credentials before using in production.
* Never use these defaults in a production environment as they are not secure.
* This is just for testing purposes.
*/
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"

// Unit tests for the application
object test extends AndroidAppTests with TestModule.Junit4 {
def mvnDeps = super.mvnDeps() ++ Seq(
mvn"junit:junit:4.13.2"
)
}

// Instrumented tests (runs on emulator)
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 mvnDeps = super.mvnDeps() ++ Seq(
mvn"androidx.test.ext:junit:1.2.1".exclude(
("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
),
mvn"androidx.test:runner:1.6.2",
mvn"androidx.test.espresso:espresso-core:3.5.1".exclude(
("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
),
mvn"junit:junit:4.13.2"
)
}

}

// <1> Create and configure an Android SDK module to manage Android SDK paths and tools.
// <2> The actual Android application

/** Usage

> ./mill show app.androidApk
".../out/app/androidApk.dest/app.apk"

> ./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.stopAndroidEmulator

> ./mill show app.deleteAndroidVirtualDevice

*/

// R8 will run automatically when you run the `androidReleaseInstall` task.
// If you want to create the APK without R8, you can use the `androidApk` task to create the not-optimized APK. You can also
// run the `andoidInstall` task that will automaticaly run the `androidApk` and also install it in the emulator.
// The `androidReleaseInstall` task will install the optimized APK on the emulator.
// So first you need to create the emulator and start it.
// After the emulator is started, you can run the `androidReleaseInstall` task and see the app in the emulator.
24 changes: 24 additions & 0 deletions example/androidlib/kotlin/1-hello-kotlin/app/proguard-rules.pro
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
# override def proguardConfigs: T[Seq[PathRef]] in build.mill

#
# 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.** { *; }
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
Loading
Loading