Skip to content
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

Hello world Kotlin Jetpack Compose Example; Fixes:#3550 #3769

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
103b7b8
Hello world Kotlin Jetpack Compose Example; Fixes:#3550
himanshumahajan138 Oct 18, 2024
d05eb8b
Merge branch 'issue-3550' of https://github.com/himanshumahajan138/mi…
himanshumahajan138 Oct 18, 2024
a73defd
Reviews Resolved ; Fixes: #3550
himanshumahajan138 Oct 19, 2024
cd32044
Fixed JsonForamtters.scala ; Fixes: #3550
himanshumahajan138 Oct 19, 2024
bfa6b1d
Revert JsonForamtters.scala ; Fixes: #3550
himanshumahajan138 Oct 19, 2024
56b1ba8
Merge branch 'main' into issue-3550
himanshumahajan138 Oct 20, 2024
dbd641e
Merge branch 'com-lihaoyi:main' into issue-3550
himanshumahajan138 Oct 20, 2024
b9ca48e
Merge branch 'main' into issue-3550
himanshumahajan138 Oct 20, 2024
2d14014
Merge branch 'main' into issue-3550
himanshumahajan138 Oct 20, 2024
d9d78b8
Merge branch 'main' into issue-3550
himanshumahajan138 Oct 21, 2024
c81b905
Final Code Updated and Docs Generated, Ready to Merge After Review; F…
himanshumahajan138 Oct 21, 2024
84875da
Final Code Updated and Docs Generated, Ready to Merge After Review; F…
himanshumahajan138 Oct 21, 2024
5bb8991
Fixed Silly Mistake (MainActivity.kt) ; Fixes: #3550
himanshumahajan138 Oct 21, 2024
e410fdd
Final Fixture
himanshumahajan138 Oct 21, 2024
5ad9ba1
Merge branch 'main' into issue-3550
himanshumahajan138 Oct 23, 2024
15d8bfd
Merge branch 'main' into issue-3550
himanshumahajan138 Oct 24, 2024
971ea8f
Whole Android Updated; Fixes:#3550
himanshumahajan138 Oct 24, 2024
b7b7b61
Merge branch 'main' into issue-3550
himanshumahajan138 Oct 26, 2024
ed45d53
Merge branch 'com-lihaoyi:main' into issue-3550
himanshumahajan138 Oct 29, 2024
041ed51
Merge branch 'com-lihaoyi:main' into issue-3550
himanshumahajan138 Oct 31, 2024
26e5cfc
Merge branch 'main' into issue-3550
himanshumahajan138 Nov 8, 2024
2c632c1
Fixture Clean
himanshumahajan138 Nov 8, 2024
8d153b7
Fixture Clean
himanshumahajan138 Nov 8, 2024
d4b436a
Merge branch 'main' into issue-3550
himanshumahajan138 Nov 9, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.helloworld.app">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="35"/>
<application android:label="Hello World" 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>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.helloworld.app

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Greeting("Hello, World!")
}
}
}

@Composable
fun Greeting(name: String) {
Text(text = name)
}
45 changes: 45 additions & 0 deletions example/kotlinlib/android/2-jetpack-compose-hello-world/build.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//// SNIPPET:BUILD
package build

import mill._
import kotlinlib._
import coursier.maven.MavenRepository
import mill.kotlinlib.android.AndroidAppKotlinModule
import mill.javalib.android.AndroidSdkModule

val maven_google = Seq(
MavenRepository("https://maven.google.com/"),
MavenRepository("https://repo1.maven.org/maven2")
)

object androidSdkModule0 extends AndroidSdkModule {
def buildToolsVersion = "35.0.0"
}

object app extends AndroidAppKotlinModule {
def kotlinVersion = "2.0.20"
def androidSdkModule = mill.define.ModuleRef(androidSdkModule0)

override def mandatoryIvyDeps: T[Agg[Dep]] = Task {
super.mandatoryIvyDeps() ++ Agg(
// Jetpack Compose dependencies
ivy"androidx.compose.compiler:compiler:1.5.15",
ivy"androidx.activity:activity:1.8.2",
ivy"androidx.activity:activity-compose:1.8.2",
ivy"androidx.compose.runtime:runtime:1.3.1",
ivy"androidx.compose.material3:material3:1.0.1"
)
}

def repositoriesTask = T.task { super.repositoriesTask() ++ maven_google }

}

////SNIPPET:END

/** Usage

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

*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package mill.kotlinlib.android

import mill.kotlinlib.KotlinModule
import mill.javalib.android.AndroidAppModule
import mill._
import coursier.Type
import upickle.default.ReadWriter

/**
* Trait for building Android applications using the Mill build tool.
Expand All @@ -18,4 +21,66 @@ import mill.javalib.android.AndroidAppModule
* [[https://developer.android.com/studio Android Studio Documentation]]
*/
@mill.api.experimental
trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule {}
trait AndroidAppKotlinModule extends AndroidAppModule with KotlinModule {
himanshumahajan138 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Implicit `ReadWriter` for serializing and deserializing `coursier.Type` values.
* Converts a `coursier.Type` to a `String` and vice versa.
*/
implicit val coursierTypeRW: ReadWriter[Type] = upickle.default.readwriter[String].bimap(
_.value, // Serialize coursier.Type to String
Type(_) // Deserialize String to coursier.Type
)

/**
* Implicit `ReadWriter` for handling `Set[coursier.Type]`, allowing conversion
* between a set of `coursier.Type` and a set of `String`.
*/
implicit val coursierTypeSetRW: ReadWriter[Set[Type]] =
upickle.default.readwriter[Set[String]].bimap(
_.map(_.value), // Serialize Set[coursier.Type] to Set[String]
_.map(Type(_)) // Deserialize Set[String] to Set[coursier.Type]
)
himanshumahajan138 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Adds the "aar" type to the set of artifact types handled by this module.
*
* @return A task that yields an updated set of artifact types including "aar".
*/
override def artifactTypes: T[Set[Type]] =
T { super.artifactTypes() + coursier.Type("aar") }

/**
* Task to extract `classes.jar` files from AAR files in the classpath.
*
* @return A sequence of `PathRef` pointing to the extracted JAR files.
*/
def recompileAARs: T[Seq[PathRef]] = Task {
himanshumahajan138 marked this conversation as resolved.
Show resolved Hide resolved
val aarFiles = super.compileClasspath().map(_.path).filter(_.ext == "aar").toSeq

aarFiles.map { aarFile =>
val extractDir = T.dest / aarFile.baseName
os.call(Seq("unzip", aarFile.toString, "-d", extractDir.toString))
PathRef(extractDir / "classes.jar")
himanshumahajan138 marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* Updates the compile classpath by removing `.aar` files and including the
* extracted `.jar` files from the AARs.
*
* @return A task yielding the updated classpath with `.jar` files.
*/
def updatedCompileClasspath: T[Agg[PathRef]] = Task {
super.compileClasspath().filter(_.path.ext == "jar") ++ Agg.from(recompileAARs())
}
himanshumahajan138 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Overrides the compile classpath to replace `.aar` files with the extracted
* `.jar` files.
*
* @return The updated classpath with `.jar` files only.
*/
override def compileClasspath: T[Agg[PathRef]] = updatedCompileClasspath()

}
Loading