Skip to content

Commit e96d05c

Browse files
authored
Merge pull request #142 from gradle/tt/add-official-agp-preview
Add init spec for AGP app using official AGP preview
2 parents b1c3ec2 + 3676aef commit e96d05c

File tree

18 files changed

+343
-1
lines changed

18 files changed

+343
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.gradle.api.experimental.android
2+
3+
class AndroidApplicationAgpPreview extends AbstractAndroidBuildInitSpec {
4+
@Override
5+
protected String getProjectSpecType() {
6+
return "android-application-agp-preview"
7+
}
8+
}

unified-prototype/unified-plugin/plugin-android-init/src/main/java/org/gradle/api/experimental/android/AndroidEcosystemInitPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public void apply(Settings settings) {
1717
getBuildInitSpecRegistry().register(StaticBuildGenerator.class, List.of(
1818
new StaticBuildSpec("android-application", "Android application with Android libraries"),
1919
new StaticBuildSpec("android-application-basic-activity", "Android Application with a basic Activity"),
20-
new StaticBuildSpec("android-application-empty-activity", "Android Application with an empty Activity")
20+
new StaticBuildSpec("android-application-empty-activity", "Android Application with an empty Activity"),
21+
new StaticBuildSpec("android-application-agp-preview", "Android Application using Official AGP Software Types Preview")
2122
));
2223
}
2324

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# declarative-samples-android-app
2+
A sample Android application written in the Declarative Gradle DSL, using the official Android Software Types Preview `androidApplication` and `androidLibrary` defined in the `com.android.ecosystem` ecosystem plugin.
3+
4+
## Building and Running
5+
6+
This sample shows the definition of a multiproject Android application implemented using Kotlin source code.
7+
8+
To build the project without running, use:
9+
10+
```shell
11+
./gradlew build
12+
```
13+
14+
To run the application, first install it on a connected Android device using:
15+
16+
```shell
17+
./gradlew :app:installDebug
18+
```
19+
20+
In IntelliJ IDEA or Android Studio you can use the `app` run configuration to launch the app in an emulator to see a hello world message.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
androidApp {
2+
namespace = "org.example.app"
3+
dependenciesDcl {
4+
implementation("org.apache.commons:commons-text:1.11.0")
5+
implementation(project(":utilities"))
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:label="@string/app_name">
4+
<activity android:name=".MainActivity">
5+
<intent-filter>
6+
<action android:name="android.intent.action.MAIN" />
7+
<category android:name="android.intent.category.LAUNCHER" />
8+
</intent-filter>
9+
</activity>
10+
</application>
11+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.example.app
2+
3+
import org.apache.commons.text.WordUtils
4+
5+
import org.example.list.LinkedList
6+
import org.example.utilities.SplitUtils
7+
import org.example.utilities.StringUtils
8+
9+
import android.widget.TextView
10+
import android.os.Bundle
11+
import android.app.Activity
12+
13+
class MainActivity : Activity() {
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
setContentView(R.layout.activity_main)
17+
18+
val textView = findViewById(R.id.textView) as TextView
19+
textView.text = buildMessage()
20+
}
21+
22+
private fun buildMessage(): String {
23+
val tokens: LinkedList
24+
tokens = SplitUtils.split(MessageUtils.message())
25+
val result: String = StringUtils.join(tokens)
26+
return WordUtils.capitalize(result)
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.example.app
2+
3+
internal object MessageUtils {
4+
fun message() = "Hello World!"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context=".MainActivity">
6+
<TextView
7+
android:id="@+id/textView"
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:layout_centerHorizontal="true"
11+
android:layout_centerVertical="true" />
12+
</RelativeLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">Sample Declarative Gradle Android App</string>
3+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.example.app
2+
3+
import org.junit.jupiter.api.Test
4+
5+
import org.junit.jupiter.api.Assertions.assertEquals
6+
7+
class MessageUtilsTest {
8+
@Test
9+
fun testGetMessage() {
10+
assertEquals("Hello World!", MessageUtils.message())
11+
}
12+
}

0 commit comments

Comments
 (0)