-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from gradle/tt/add-official-agp-preview
Add init spec for AGP app using official AGP preview
- Loading branch information
Showing
18 changed files
with
343 additions
and
1 deletion.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
.../integTest/groovy/org/gradle/api/experimental/android/AndroidApplicationAgpPreview.groovy
This file contains 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 org.gradle.api.experimental.android | ||
|
||
class AndroidApplicationAgpPreview extends AbstractAndroidBuildInitSpec { | ||
@Override | ||
protected String getProjectSpecType() { | ||
return "android-application-agp-preview" | ||
} | ||
} |
This file contains 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
20 changes: 20 additions & 0 deletions
20
...oid-init/src/main/resources/templates/android-application-agp-preview/README.md
This file contains 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 @@ | ||
# declarative-samples-android-app | ||
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. | ||
|
||
## Building and Running | ||
|
||
This sample shows the definition of a multiproject Android application implemented using Kotlin source code. | ||
|
||
To build the project without running, use: | ||
|
||
```shell | ||
./gradlew build | ||
``` | ||
|
||
To run the application, first install it on a connected Android device using: | ||
|
||
```shell | ||
./gradlew :app:installDebug | ||
``` | ||
|
||
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. |
7 changes: 7 additions & 0 deletions
7
...id-init/src/main/resources/templates/android-application-agp-preview/app/build.gradle.dcl
This file contains 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,7 @@ | ||
androidApp { | ||
namespace = "org.example.app" | ||
dependenciesDcl { | ||
implementation("org.apache.commons:commons-text:1.11.0") | ||
implementation(project(":utilities")) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...main/resources/templates/android-application-agp-preview/app/src/main/AndroidManifest.xml
This file contains 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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<application android:label="@string/app_name"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
28 changes: 28 additions & 0 deletions
28
...lates/android-application-agp-preview/app/src/main/kotlin/org/example/app/MainActivity.kt
This file contains 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,28 @@ | ||
package org.example.app | ||
|
||
import org.apache.commons.text.WordUtils | ||
|
||
import org.example.list.LinkedList | ||
import org.example.utilities.SplitUtils | ||
import org.example.utilities.StringUtils | ||
|
||
import android.widget.TextView | ||
import android.os.Bundle | ||
import android.app.Activity | ||
|
||
class MainActivity : Activity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
val textView = findViewById(R.id.textView) as TextView | ||
textView.text = buildMessage() | ||
} | ||
|
||
private fun buildMessage(): String { | ||
val tokens: LinkedList | ||
tokens = SplitUtils.split(MessageUtils.message()) | ||
val result: String = StringUtils.join(tokens) | ||
return WordUtils.capitalize(result) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...lates/android-application-agp-preview/app/src/main/kotlin/org/example/app/MessageUtils.kt
This file contains 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,5 @@ | ||
package org.example.app | ||
|
||
internal object MessageUtils { | ||
fun message() = "Hello World!" | ||
} |
12 changes: 12 additions & 0 deletions
12
...urces/templates/android-application-agp-preview/app/src/main/res/layout/activity_main.xml
This file contains 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,12 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
<TextView | ||
android:id="@+id/textView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerHorizontal="true" | ||
android:layout_centerVertical="true" /> | ||
</RelativeLayout> |
3 changes: 3 additions & 0 deletions
3
...n/resources/templates/android-application-agp-preview/app/src/main/res/values/strings.xml
This file contains 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,3 @@ | ||
<resources> | ||
<string name="app_name">Sample Declarative Gradle Android App</string> | ||
</resources> |
12 changes: 12 additions & 0 deletions
12
...s/android-application-agp-preview/app/src/test/kotlin/org/example/app/MessageUtilsTest.kt
This file contains 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,12 @@ | ||
package org.example.app | ||
|
||
import org.junit.jupiter.api.Test | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
|
||
class MessageUtilsTest { | ||
@Test | ||
fun testGetMessage() { | ||
assertEquals("Hello World!", MessageUtils.message()) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...droid-init/src/main/resources/templates/android-application-agp-preview/gradle.properties
This file contains 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,6 @@ | ||
org.gradle.caching=true | ||
org.gradle.parallel=true | ||
org.gradle.configuration-cache=true | ||
kotlin.code.style=official | ||
android.experimental.declarative=true | ||
android.useAndroidX=true |
3 changes: 3 additions & 0 deletions
3
...d-init/src/main/resources/templates/android-application-agp-preview/list/build.gradle.dcl
This file contains 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,3 @@ | ||
androidLibrary { | ||
namespace = "org.gradle.experimental.android.list" | ||
} |
86 changes: 86 additions & 0 deletions
86
...lates/android-application-agp-preview/list/src/main/kotlin/org/example/list/LinkedList.kt
This file contains 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,86 @@ | ||
package org.example.list | ||
|
||
class LinkedList { | ||
private var head: Node? = null | ||
|
||
fun add(element: String?) { | ||
val newNode = Node(element) | ||
|
||
val it = tail(head) | ||
if (it == null) { | ||
head = newNode | ||
} else { | ||
it.next = newNode | ||
} | ||
} | ||
|
||
fun remove(element: String): Boolean { | ||
var result = false | ||
var previousIt: Node? = null | ||
var it: Node? | ||
it = head | ||
while (!result && it != null) { | ||
if (0 == element.compareTo(it.data!!)) { | ||
result = true | ||
unlink(previousIt, it) | ||
break | ||
} | ||
previousIt = it | ||
it = it.next | ||
} | ||
|
||
return result | ||
} | ||
|
||
private fun unlink(previousIt: Node?, currentIt: Node) { | ||
if (currentIt === head) { | ||
head = currentIt.next | ||
} else { | ||
previousIt!!.next = currentIt.next | ||
} | ||
} | ||
|
||
fun size(): Int { | ||
var size = 0 | ||
|
||
var it = head | ||
while (it != null) { | ||
++size | ||
it = it.next | ||
} | ||
|
||
return size | ||
} | ||
|
||
fun get(index: Int): String? { | ||
var currIdx = index | ||
var it = head | ||
while (currIdx > 0 && it != null) { | ||
it = it.next | ||
currIdx-- | ||
} | ||
|
||
if (it == null) { | ||
throw java.lang.IndexOutOfBoundsException("Index is out of range") | ||
} | ||
|
||
return it.data | ||
} | ||
|
||
private class Node(val data: String?) { | ||
var next: Node? = null | ||
} | ||
|
||
companion object { | ||
private fun tail(head: Node?): Node? { | ||
var it: Node? | ||
|
||
it = head | ||
while (it?.next != null) { | ||
it = it.next | ||
} | ||
|
||
return it | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...oid-init/src/main/resources/templates/android-application-agp-preview/settings.gradle.dcl
This file contains 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,68 @@ | ||
pluginManagement { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
maven { | ||
url = uri("https://androidx.dev/studio/builds/12648882/artifacts/artifacts/repository") | ||
} | ||
} | ||
} | ||
|
||
plugins { | ||
id("com.android.ecosystem").version("8.9.0-dev") | ||
} | ||
|
||
dependencyResolutionManagement { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
maven { | ||
url = uri("https://androidx.dev/studio/builds/12648882/artifacts/artifacts/repository") | ||
} | ||
} | ||
} | ||
|
||
rootProject.name = "example-android-app" | ||
|
||
include("app") | ||
include("list") | ||
include("utilities") | ||
|
||
defaults { | ||
androidApp { | ||
compileSdk = 34 | ||
compileOptions { | ||
sourceCompatibility = VERSION_17 | ||
targetCompatibility = VERSION_17 | ||
} | ||
defaultConfig { | ||
minSdk = 30 | ||
versionCode = 1 | ||
versionName = "0.1" | ||
applicationId = "org.gradle.experimental.android.app" | ||
} | ||
dependenciesDcl { | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21") | ||
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2") | ||
testImplementation("org.junit.platform:junit-platform-launcher") | ||
androidTestImplementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21") | ||
} | ||
} | ||
|
||
androidLibrary { | ||
compileSdk = 34 | ||
compileOptions { | ||
sourceCompatibility = VERSION_17 | ||
targetCompatibility = VERSION_17 | ||
} | ||
defaultConfig { | ||
minSdk = 30 | ||
} | ||
dependenciesDcl { | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21") | ||
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2") | ||
testImplementation("org.junit.platform:junit-platform-launcher") | ||
androidTestImplementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21") | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...t/src/main/resources/templates/android-application-agp-preview/utilities/build.gradle.dcl
This file contains 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,6 @@ | ||
androidLibrary { | ||
namespace = "org.gradle.experimental.android.utilities" | ||
dependenciesDcl { | ||
api(project(":list")) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...roid-application-agp-preview/utilities/src/main/kotlin/org/example/utilities/JoinUtils.kt
This file contains 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,17 @@ | ||
package org.example.utilities | ||
|
||
import org.example.list.LinkedList | ||
|
||
internal object JoinUtils { | ||
fun join(source: LinkedList): String { | ||
val result: java.lang.StringBuilder = java.lang.StringBuilder() | ||
for (i in 0 until source.size()) { | ||
if (result.length > 0) { | ||
result.append(" ") | ||
} | ||
result.append(source.get(i)) | ||
} | ||
|
||
return result.toString() | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...oid-application-agp-preview/utilities/src/main/kotlin/org/example/utilities/SplitUtils.kt
This file contains 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,36 @@ | ||
package org.example.utilities | ||
|
||
import org.example.list.LinkedList | ||
|
||
object SplitUtils { | ||
fun split(source: String): LinkedList { | ||
var lastFind = 0 | ||
var currentFind: Int | ||
val result: LinkedList = LinkedList() | ||
|
||
while ((source.indexOf(" ", lastFind).also { currentFind = it }) != -1) { | ||
var token: String = source.substring(lastFind) | ||
if (currentFind != -1) { | ||
token = token.substring(0, currentFind - lastFind) | ||
} | ||
|
||
addIfValid(token, result) | ||
lastFind = currentFind + 1 | ||
} | ||
|
||
val token: String = source.substring(lastFind) | ||
addIfValid(token, result) | ||
|
||
return result | ||
} | ||
|
||
private fun addIfValid(token: String, list: LinkedList) { | ||
if (isTokenValid(token)) { | ||
list.add(token) | ||
} | ||
} | ||
|
||
private fun isTokenValid(token: String): Boolean { | ||
return !token.isEmpty() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...id-application-agp-preview/utilities/src/main/kotlin/org/example/utilities/StringUtils.kt
This file contains 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,13 @@ | ||
package org.example.utilities | ||
|
||
import org.example.list.LinkedList | ||
|
||
object StringUtils { | ||
fun join(source: LinkedList): String { | ||
return JoinUtils.join(source) | ||
} | ||
|
||
fun split(source: String): LinkedList { | ||
return SplitUtils.split(source) | ||
} | ||
} |