- In a terminal window, edit your .bashrc file to set your PATH and other environment variables.
export PATH=/home/$USER/android-studio/gradle/gradle-2.2.1/bin:$PATH:/home/$USER/Android/Sdk/tools:/home/$USER/Android/Sdk/platform-tools:/home/$USER/bin
export ANDROID_SDK_HOME=/home/$USER/Android/Sdk
export HISTTIMEFORMAT='%F %T '
export HISTSIZE=2000
- You should now be able to run the gradle command without the ./ prefix. Try running this command to verify:
gradle -h
- Unless it complains it's not executable, use the "chmod +x " command to add execute permissions to that file.
- Try the following commands to ensure they work. If they don't then adjust your environment in step 1 or install missing software. Also read the output from the adb/android commands to get an idea of what they are used for:
java -version
javac -version
adb -h
android -h
- We now need to create some basic source code so we can build it into an Android app. Use the mkdir command to create a source tree that looks like this (you can download the files you need here:
.
├── build.gradle
├── local.properties
└── src
└── main
├── AndroidManifest.xml
├── java
│ └── org
│ └── hello
│ └── HelloActivity.java
└── res
├── layout
│ └── hello_layout.xml
└── values
└── strings.xml
- Finally you'll need to create a Gradle build file inside your project directory. The name of this file is "build.gradle" and it looks like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "org.hello"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
}
- You can now use Gradle to build your app. Just run this command from inside your project directory.
gradle build
- Before you move on to PART C, try "gradle --help" to see what else gradle can do. If the build was successful you can run the Bash tree command to get a bird's eye view of what files/directories were created by the build. Save this tree output, you'll need it for PART D of this lab.