Building Android Apps Sample
version 6.8.3
You can open this sample inside a Android Studio IDE using the project importer. |
This sample shows how a simple Android application written in Java can be built with Gradle. The application was created following the Build your first app guide.
app/build.gradle
plugins {
id('com.android.application') version '4.1.1'
}
repositories {
google()
jcenter()
}
android {
compileSdkVersion 30
buildToolsVersion '30.0.1'
defaultConfig {
applicationId 'org.gradle.samples'
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName '1.0'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
app/build.gradle.kts
plugins {
id("com.android.application") version "4.1.1"
}
repositories {
google()
jcenter()
}
android {
compileSdkVersion(30)
buildToolsVersion("30.0.1")
defaultConfig {
applicationId = "org.gradle.samples"
minSdkVersion(16)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
}
dependencies {
implementation("androidx.appcompat:appcompat:1.1.0")
implementation("com.google.android.material:material:1.1.0")
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
implementation("androidx.navigation:navigation-fragment-ktx:2.2.2")
implementation("androidx.navigation:navigation-ui-ktx:2.2.2")
testImplementation("junit:junit:4.13")
androidTestImplementation("androidx.test.ext:junit:1.1.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.2.0")
}
To build the application:
$ ./gradlew build
For more information, we suggest reading Getting Started with Gradle. You can also find Android development related information inside the guides provided by the Android team.