Android: Allow building of native libraries inside Android Studio / Gradle
This commit is contained in:
parent
7e6ec5fa86
commit
9c19d91e18
22
Readme.md
22
Readme.md
|
@ -56,18 +56,22 @@ Gradle task `assembleDebug` to build, or `installDebug` to install the UI onto a
|
|||
|
||||
In order to launch the app, you must build and include the native Dolphin libraries into the UI project.
|
||||
Building native code requires the [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html).
|
||||
Android Studio will do this for you if you create `Source/Android/build.properties`, and place the
|
||||
following inside:
|
||||
|
||||
### Build Steps:
|
||||
1. `mkdir Build-Android-<abi>`
|
||||
2. `cd Build-Android-<abi>`
|
||||
3. `cmake -DANDROID=True -DANDROID_NDK=<ndk-path> -DANDROID_NATIVE_API_LEVEL=android-18 -DANDROID_TOOLCHAIN_NAME=<toolchain> -DANDROID_ABI=<abi> -DCMAKE_TOOLCHAIN_FILE=../Source/Android/android.toolchain.cmake -DGIT_EXECUTABLE=<git-path> ..`
|
||||
4. `make`
|
||||
```
|
||||
gitPath=<git-path>
|
||||
ndkPath=<ndk-path>
|
||||
toolchain=<toolchain>
|
||||
abi=<abi>
|
||||
makeArgs=<make-args>
|
||||
```
|
||||
|
||||
Replace `<git-path>` with the absolute path to your machine's Git executable, <ndk-path> with the absolute
|
||||
path to where you installed your NDK, and the rest depending on which platform the Android device you are
|
||||
targeting uses:
|
||||
Replace `<git-path>` with the absolute path to your machine's Git executable, `<ndk-path>` with the absolute
|
||||
path to where you installed your NDK, `<make-args>` with any arguments you want to pass to `make`, and the
|
||||
rest depending on which platform the Android device you are targeting uses:
|
||||
|
||||
|Platform | abi | toolchain |
|
||||
|Platform | `<abi>` | `<toolchain>` |
|
||||
|-------------------------|-------------|---------------------------|
|
||||
|ARM 32-bit (most devices)| armeabi-v7a | arm-linux-androideabi-4.9 |
|
||||
|ARM 64-bit (i.e. Nexus 9)| arm64-v8a | aarch64-linux-android-4.9 |
|
||||
|
|
|
@ -40,3 +40,4 @@ gradle/
|
|||
build/
|
||||
*.so
|
||||
*.iml
|
||||
build.properties
|
|
@ -41,6 +41,10 @@ android {
|
|||
applicationIdSuffix ".debug"
|
||||
versionNameSuffix '-debug'
|
||||
jniDebuggable true
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
compileTask -> compileTask.dependsOn(compileNative)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,3 +62,53 @@ dependencies {
|
|||
// For loading huge screenshots from the disk.
|
||||
compile 'com.squareup.picasso:picasso:2.5.2'
|
||||
}
|
||||
|
||||
task setupCMake(type: Exec) {
|
||||
// Check if a build properties file exists.
|
||||
def propsFile = rootProject.file("build.properties")
|
||||
|
||||
// If it does, call CMake.
|
||||
if (propsFile.canRead()) {
|
||||
// Read the properties file's contents.
|
||||
def buildProperties = new Properties()
|
||||
buildProperties.load(new FileInputStream(propsFile))
|
||||
|
||||
mkdir('build/' + buildProperties.abi)
|
||||
workingDir 'build/' + buildProperties.abi
|
||||
|
||||
executable 'cmake'
|
||||
|
||||
args "-DANDROID=true",
|
||||
"-DANDROID_NATIVE_API_LEVEL=android-18",
|
||||
"-DCMAKE_TOOLCHAIN_FILE=../../../android.toolchain.cmake",
|
||||
"../../../../..",
|
||||
"-DGIT_EXECUTABLE=" + buildProperties.gitPath,
|
||||
"-DANDROID_NDK=" + buildProperties.ndkPath,
|
||||
"-DANDROID_TOOLCHAIN_NAME=" + buildProperties.toolchain,
|
||||
"-DANDROID_ABI=" + buildProperties.abi
|
||||
} else {
|
||||
executable 'echo'
|
||||
args 'No build.properties found; skipping CMake.'
|
||||
}
|
||||
}
|
||||
|
||||
task compileNative(type: Exec, dependsOn: 'setupCMake') {
|
||||
// Check if a build properties file exists.
|
||||
def propsFile = rootProject.file("build.properties")
|
||||
|
||||
// If it does, call make.
|
||||
if (propsFile.canRead()) {
|
||||
// Read the properties file's contents.
|
||||
def buildProperties = new Properties()
|
||||
buildProperties.load(new FileInputStream(propsFile))
|
||||
|
||||
workingDir 'build/' + buildProperties.abi
|
||||
|
||||
executable 'make'
|
||||
|
||||
args buildProperties.makeArgs
|
||||
} else {
|
||||
executable 'echo'
|
||||
args 'No build.properties found; skipping native build.'
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue