Skip to content

Commit 05eff01

Browse files
committed
Android: Update the gradle file to use android studio 2.2 cmake.
1 parent abb5a64 commit 05eff01

File tree

14 files changed

+59
-332
lines changed

14 files changed

+59
-332
lines changed

AndroidSetup.md

+5-23
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@ If you'd like to contribute to the Android project, but do not currently have a
44

55
## Prerequisites
66

7-
* A Linux VM or host, or a Mac.
8-
* JDK 7 for your platform.
9-
* CMake
10-
* [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html)
11-
* [Android Studio](http://developer.android.com/tools/studio/index.html) **OR**
12-
* [Android SDK Tools](http://developer.android.com/sdk/index.html#Other) (for command-line usage)
7+
* [Android Studio](http://developer.android.com/tools/studio/index.html)
138

149
If you downloaded Android Studio, extract it and then see [Setting up Android Studio](#setting-up-android-studio).
1510

16-
If you instead chose to download the commoand-line SDK tools, see [Setting up the SDK Tools](#setting-up-the-sdk-tools).
17-
1811
## Setting up Android Studio
1912

2013
1. Launch Android Studio, which will start a first-launch wizard.
@@ -26,12 +19,6 @@ If you instead chose to download the commoand-line SDK tools, see [Setting up th
2619
7. Use the SDK Manager to get necessary dependencies, as described in [Getting Dependencies](#getting-dependencies).
2720
8. When done, follow the steps in [Readme.md](Readme.md#installation-on-android) to compile and deploy the application.
2821

29-
## Setting up the SDK Tools
30-
31-
1. In `Source/Android`, create a file called `local.properties`.
32-
2. Add a single line: `sdk.dir=<sdk-path>`, where `<sdk-path>` is the path where you extracted the SDK Tools package.
33-
3. Follow the steps in [Readme.md](Readme.md#installation-on-android) to compile and deploy the application.
34-
3522
## Executing Gradle Tasks
3623

3724
In Android Studio, you can find a list of possible Gradle tasks in a tray at the top right of the screen:
@@ -50,19 +37,14 @@ For command-line users, any task may be executed with `Source/Android/gradlew <t
5037

5138
Most dependencies for the Android project are supplied by Gradle automatically. However, Android platform libraries (and a few Google-supplied supplementary libraries) must be downloaded through the Android package manager.
5239

53-
1. Launch the Android SDK Manager from the commandline by executing `<sdk-path>/tools/android`, or by clicking on its icon in Android Studio's main toolbar:
40+
1. Launch the Android SDK Manager by clicking on its icon in Android Studio's main toolbar:
5441
![Android Studio Package Icon][package-icon]
55-
2. At the bottom of the window, click "Deselect All", and then "Updates".
56-
3. Install or update the following packages:
57-
58-
* SDK Platform, under "Android 5.0.1 (API 21)". This will allow compiling apps that target Lollipop.
59-
* Android Support Repository
60-
* Android Support Library
61-
* Google Repository
42+
2. Install or update the SDK Platform. Choose the API level selected as [compileSdkVersion](Source/Android/app/build.gradle#L5).
43+
3. Install or update the SDK Tools. CMake, LLDB and NDK. If you don't use android-studio, please check out https://github.com/Commit451/android-cmake-installer.
6244

6345
In the future, if the project targets a newer version of Android, or use newer versions of the tools/build-tools packages, it will be necessary to use this tool to download updates.
6446

6547
[components]: http://i.imgur.com/Oo1Fs93.png
6648
[package-icon]: http://i.imgur.com/NUpkAH8.png
6749
[gradle]: http://i.imgur.com/dXIH6o3.png
68-
[shortcut]: http://i.imgur.com/eCWP4Yy.png
50+
[shortcut]: http://i.imgur.com/eCWP4Yy.png

CMakeLists.txt

+19-25
Original file line numberDiff line numberDiff line change
@@ -188,36 +188,28 @@ else()
188188
add_definitions(-D_ARCH_32=1)
189189
endif()
190190

191-
if(NOT ENABLE_GENERIC)
192-
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86" OR
193-
${CMAKE_SYSTEM_PROCESSOR} MATCHES "i.86" OR
194-
${CMAKE_SYSTEM_PROCESSOR} MATCHES "amd64" OR
195-
APPLE)
196-
if(_ARCH_64)
197-
set(_M_X86 1)
198-
set(_M_X86_64 1)
199-
add_definitions(-D_M_X86=1 -D_M_X86_64=1 -msse2)
200-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
201-
else()
202-
message(FATAL_ERROR "x86_32 is an unsupported platform. Enable generic build if you really want a JIT-less binary.")
203-
endif()
204-
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
205-
message(FATAL_ERROR "ARMv7 is an unsupported platform. Enable generic build if you really want a JIT-less binary.")
206-
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
207-
# This option only applies to 64bit ARM
208-
set(_M_ARM 1)
209-
set(_M_ARM_64 1)
210-
add_definitions(-D_M_ARM=1 -D_M_ARM_64=1)
211-
add_definitions(-march=armv8-a+crc)
212-
else()
213-
set(ENABLE_GENERIC 1)
214-
endif()
215-
endif()
216191

217192
if(ENABLE_GENERIC)
218193
message("Warning! Building generic build!")
219194
set(_M_GENERIC 1)
220195
add_definitions(-D_M_GENERIC=1)
196+
elseif(_ARCH_64 AND (
197+
${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86" OR
198+
${CMAKE_SYSTEM_PROCESSOR} MATCHES "i.86" OR
199+
${CMAKE_SYSTEM_PROCESSOR} MATCHES "amd64" OR
200+
APPLE
201+
))
202+
set(_M_X86 1)
203+
set(_M_X86_64 1)
204+
add_definitions(-D_M_X86=1 -D_M_X86_64=1 -msse2)
205+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie")
206+
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
207+
set(_M_ARM 1)
208+
set(_M_ARM_64 1)
209+
add_definitions(-D_M_ARM=1 -D_M_ARM_64=1)
210+
add_definitions(-march=armv8-a+crc)
211+
else()
212+
message(FATAL_ERROR "You're building on an unsupported platform. Enable generic build if you really want a JIT-less binary.")
221213
endif()
222214

223215
include(CheckCXXCompilerFlag)
@@ -423,6 +415,8 @@ if(ANDROID)
423415
# We are cross compiling, search only the toolchain for libraries and includes
424416
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
425417
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
418+
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
419+
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
426420
elseif(NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES OpenBSD)
427421
list(APPEND LIBS rt)
428422
endif()

Readme.md

+1-23
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,7 @@ If using Android Studio, import the Gradle project located in `./Source/Android`
9999

100100
Android apps are compiled using a build system called Gradle. Dolphin's native component,
101101
however, is compiled using CMake. The Gradle script will attempt to run a CMake build
102-
automatically while building the Java code, if you create the file `Source/Android/build.properties`,
103-
and place the following inside:
104-
105-
```
106-
# Specifies arguments for the 'make' command. Can be blank.
107-
makeArgs=
108-
109-
# The path to your machine's Git executable. Will autodetect if blank (on Linux only).
110-
gitPath=
111-
112-
# The path to the CMake executable. Will autodetect if blank (on Linux only).
113-
cmakePath=
114-
115-
# The path to the extracted NDK package. Will autodetect if blank (on Linux only).
116-
ndkPath=
117-
```
118-
119-
If you prefer, you can run the CMake step manually, and it will copy the resulting
120-
binary into the correct location for inclusion in the Android APK.
121-
122-
Execute the Gradle task `assembleArm_64Debug` to build, or `installArm_64Debug` to
123-
install the application onto a connected device. If other ABIs are eventually supported,
124-
execute the tasks corresponding to the desired ABI.
102+
automatically while building the Java code.
125103

126104
## Uninstalling
127105
When Dolphin has been installed with the NSIS installer, you can uninstall

Source/Android/app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/build
2+
/.externalNativeBuild

Source/Android/app/build.gradle

+18-191
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ apply plugin: 'com.android.application'
22

33
android {
44
// Leanback support requires >22
5-
compileSdkVersion 23
6-
buildToolsVersion '23.0.2'
5+
compileSdkVersion 24
6+
buildToolsVersion '24.0.3'
77

88
lintOptions {
99
// This is important as it will run lint but not abort on error
@@ -53,213 +53,40 @@ android {
5353
applicationIdSuffix ".debug"
5454
versionNameSuffix '-debug'
5555
jniDebuggable true
56-
57-
tasks.withType(JavaCompile) {
58-
compileTask -> compileTask.dependsOn(compileNative)
59-
}
6056
}
6157
}
6258

63-
// Define product flavors, which can be split into categories. Common examples
64-
// of product flavors are paid vs. free, ARM vs. x86, etc.
65-
productFlavors {
66-
arm_64 {
67-
dimension "abi"
68-
ndk {
69-
abiFilter "arm64-v8a"
70-
}
59+
externalNativeBuild {
60+
cmake {
61+
path "../../../CMakeLists.txt"
7162
}
63+
}
7264

73-
x86_64 {
74-
dimension "abi"
75-
ndk {
76-
abiFilter "x86_64"
65+
defaultConfig {
66+
externalNativeBuild {
67+
cmake {
68+
arguments "-DANDROID_STL=c++_static", "-DCMAKE_BUILD_TYPE=RelWithDebInfo", "-DENABLE_PCH=OFF" // , "-DENABLE_GENERIC=ON"
69+
abiFilters "arm64-v8a" //, "armeabi-v7a", "x86_64", "x86"
7770
}
7871
}
7972
}
8073
}
8174

8275
dependencies {
83-
compile 'com.android.support:support-v13:23.1.1'
84-
compile 'com.android.support:cardview-v7:23.1.1'
85-
compile 'com.android.support:recyclerview-v7:23.1.1'
86-
compile 'com.android.support:design:23.1.1'
76+
compile 'com.android.support:support-v13:24.2.1'
77+
compile 'com.android.support:cardview-v7:24.2.1'
78+
compile 'com.android.support:recyclerview-v7:24.2.1'
79+
compile 'com.android.support:design:24.2.1'
8780

8881
// Android TV UI libraries.
89-
compile 'com.android.support:leanback-v17:23.1.1'
82+
compile 'com.android.support:leanback-v17:24.2.1'
9083

9184
// For showing the banner as a circle a-la Material Design Guidelines
92-
compile 'de.hdodenhof:circleimageview:1.2.2'
85+
compile 'de.hdodenhof:circleimageview:2.1.0'
9386

9487
// For loading huge screenshots from the disk.
9588
compile 'com.squareup.picasso:picasso:2.5.2'
9689

9790
// Allows FRP-style asynchronous operations in Android.
98-
compile 'io.reactivex:rxandroid:1.1.0'
99-
}
100-
101-
task setupCMake(type: Exec) {
102-
// Check if a build properties file exists.
103-
def propsFile = rootProject.file("build.properties")
104-
105-
// If it does, call CMake.
106-
if (propsFile.canRead()) {
107-
// Read the properties file's contents.
108-
def buildProperties = new Properties()
109-
buildProperties.load(new FileInputStream(propsFile))
110-
111-
String abi = getAbi()
112-
113-
mkdir('build/' + abi)
114-
workingDir 'build/' + abi
115-
116-
executable getExecutablePath("cmake")
117-
118-
args "-DANDROID=true",
119-
"-DANDROID_NATIVE_API_LEVEL=android-18",
120-
"-DCMAKE_TOOLCHAIN_FILE=../../../android.toolchain.cmake",
121-
"../../../../..",
122-
"-DGIT_EXECUTABLE=" + getExecutablePath("git"),
123-
"-DANDROID_NDK=" + getNdkPath(),
124-
"-DANDROID_TOOLCHAIN_NAME=" + getToolchainName(),
125-
"-DANDROID_ABI=" + abi
126-
} else {
127-
executable 'echo'
128-
args 'No build.properties found; skipping CMake.'
129-
}
91+
compile 'io.reactivex:rxandroid:1.2.1'
13092
}
131-
132-
task compileNative(type: Exec, dependsOn: 'setupCMake') {
133-
// Check if a build properties file exists.
134-
def propsFile = rootProject.file("build.properties")
135-
136-
// If it does, call make.
137-
if (propsFile.canRead()) {
138-
// Read the properties file's contents.
139-
def buildProperties = new Properties()
140-
buildProperties.load(new FileInputStream(propsFile))
141-
142-
String abi = getAbi()
143-
144-
workingDir 'build/' + abi
145-
146-
executable 'make'
147-
148-
if (buildProperties.makeArgs == null || buildProperties.makeArgs.isEmpty()) {
149-
// TODO
150-
} else {
151-
args buildProperties.makeArgs
152-
}
153-
} else {
154-
executable 'echo'
155-
args 'No build.properties found; skipping native build.'
156-
}
157-
}
158-
159-
String getExecutablePath(String command) {
160-
def propsFile = rootProject.file("build.properties")
161-
def path = null
162-
163-
if (propsFile.canRead()) {
164-
def buildProperties = new Properties()
165-
buildProperties.load(new FileInputStream(propsFile))
166-
println buildProperties
167-
path = buildProperties[command + "Path"]
168-
}
169-
170-
if (path == null || path.isEmpty()) {
171-
try {
172-
def stdout = new ByteArrayOutputStream()
173-
174-
exec {
175-
commandLine 'which', command
176-
standardOutput = stdout
177-
}
178-
179-
path = stdout.toString().trim()
180-
} catch (ignored) {
181-
project.logger.error("Gradle error: Couldn't find " + command + " executable.")
182-
}
183-
}
184-
185-
if (path != null) {
186-
project.logger.quiet("Gradle: Found " + command + " executuable:" + path)
187-
}
188-
189-
return path
190-
}
191-
192-
String getNdkPath() {
193-
def propsFile = rootProject.file("build.properties")
194-
def ndkPath = null
195-
196-
if (propsFile.canRead()) {
197-
def buildProperties = new Properties()
198-
buildProperties.load(new FileInputStream(propsFile))
199-
ndkPath = buildProperties.ndkPath
200-
}
201-
202-
if (ndkPath == null || ndkPath.isEmpty()) {
203-
try {
204-
def stdout = new ByteArrayOutputStream()
205-
206-
exec {
207-
// ndk-build.cmd is a file unique to the root directory of android-ndk-r10e.
208-
commandLine 'locate', 'ndk-build.cmd'
209-
standardOutput = stdout
210-
}
211-
212-
def ndkCmdPath = stdout.toString()
213-
ndkPath = ndkCmdPath.substring(0, ndkCmdPath.lastIndexOf('/'))
214-
} catch (ignored) {
215-
project.logger.error("Gradle error: Couldn't find NDK.")
216-
}
217-
}
218-
219-
if (ndkPath != null) {
220-
project.logger.quiet("Gradle: Found Android NDK: " + ndkPath)
221-
}
222-
return ndkPath
223-
}
224-
225-
String getAbi() {
226-
String taskName = getGradle().startParameter.taskNames[0]
227-
String abi;
228-
229-
if (taskName == null) {
230-
return ""
231-
}
232-
233-
project.logger.quiet("Gradle: Build = " + taskName)
234-
235-
if (taskName.contains("Arm_64")) {
236-
abi = "arm64-v8a"
237-
} else if (taskName.contains("Arm")) {
238-
abi = "armeabi-v7a"
239-
} else if (taskName.contains("X86_64")) {
240-
abi = "x86_64"
241-
}
242-
243-
project.logger.quiet("Gradle: ABI name: " + abi)
244-
return abi;
245-
}
246-
247-
String getToolchainName() {
248-
String taskName = getGradle().startParameter.taskNames[0]
249-
String toolchain;
250-
251-
if (taskName == null) {
252-
return ""
253-
}
254-
255-
if (taskName.contains("Arm_64")) {
256-
toolchain = "aarch64-linux-android-4.9"
257-
} else if (taskName.contains("Arm")) {
258-
toolchain = "arm-linux-androideabi-4.9"
259-
} else if (taskName.contains("X86_64")) {
260-
toolchain = "x86_64-4.9"
261-
}
262-
263-
project.logger.quiet("Gradle: ABI name: " + toolchain)
264-
return toolchain;
265-
}

0 commit comments

Comments
 (0)