From 05eff01229c8552871c3613c0115a91f22cf8dd6 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 8 Jun 2016 19:49:46 +0200 Subject: [PATCH] Android: Update the gradle file to use android studio 2.2 cmake. --- AndroidSetup.md | 28 +-- CMakeLists.txt | 44 ++-- Readme.md | 24 +- Source/Android/app/.gitignore | 1 + Source/Android/app/build.gradle | 209 ++---------------- .../app/src/arm_64/res/values/arrays.xml | 18 -- .../app/src/arm_64/res/values/strings.xml | 5 - .../main/res/layout/dialog_game_details.xml | 4 +- .../app/src/main/res/values/arrays.xml | 6 + .../app/src/x86_64/res/values/arrays.xml | 18 -- Source/Android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- Source/Android/jni/CMakeLists.txt | 24 +- Source/UnitTests/CMakeLists.txt | 4 +- 14 files changed, 59 insertions(+), 332 deletions(-) delete mode 100644 Source/Android/app/src/arm_64/res/values/arrays.xml delete mode 100644 Source/Android/app/src/arm_64/res/values/strings.xml delete mode 100644 Source/Android/app/src/x86_64/res/values/arrays.xml diff --git a/AndroidSetup.md b/AndroidSetup.md index 5dfa85d5a9..3a2b754dd5 100644 --- a/AndroidSetup.md +++ b/AndroidSetup.md @@ -4,17 +4,10 @@ If you'd like to contribute to the Android project, but do not currently have a ## Prerequisites -* A Linux VM or host, or a Mac. -* JDK 7 for your platform. -* CMake -* [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html) -* [Android Studio](http://developer.android.com/tools/studio/index.html) **OR** -* [Android SDK Tools](http://developer.android.com/sdk/index.html#Other) (for command-line usage) +* [Android Studio](http://developer.android.com/tools/studio/index.html) If you downloaded Android Studio, extract it and then see [Setting up Android Studio](#setting-up-android-studio). -If you instead chose to download the commoand-line SDK tools, see [Setting up the SDK Tools](#setting-up-the-sdk-tools). - ## Setting up Android Studio 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 7. Use the SDK Manager to get necessary dependencies, as described in [Getting Dependencies](#getting-dependencies). 8. When done, follow the steps in [Readme.md](Readme.md#installation-on-android) to compile and deploy the application. -## Setting up the SDK Tools - -1. In `Source/Android`, create a file called `local.properties`. -2. Add a single line: `sdk.dir=`, where `` is the path where you extracted the SDK Tools package. -3. Follow the steps in [Readme.md](Readme.md#installation-on-android) to compile and deploy the application. - ## Executing Gradle Tasks 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 /tools/android`, or by clicking on its icon in Android Studio's main toolbar: +1. Launch the Android SDK Manager by clicking on its icon in Android Studio's main toolbar: ![Android Studio Package Icon][package-icon] -2. At the bottom of the window, click "Deselect All", and then "Updates". -3. Install or update the following packages: - -* SDK Platform, under "Android 5.0.1 (API 21)". This will allow compiling apps that target Lollipop. -* Android Support Repository -* Android Support Library -* Google Repository +2. Install or update the SDK Platform. Choose the API level selected as [compileSdkVersion](Source/Android/app/build.gradle#L5). +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. 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. [components]: http://i.imgur.com/Oo1Fs93.png [package-icon]: http://i.imgur.com/NUpkAH8.png [gradle]: http://i.imgur.com/dXIH6o3.png -[shortcut]: http://i.imgur.com/eCWP4Yy.png \ No newline at end of file +[shortcut]: http://i.imgur.com/eCWP4Yy.png diff --git a/CMakeLists.txt b/CMakeLists.txt index 93dc457fed..656198e124 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,36 +188,28 @@ else() add_definitions(-D_ARCH_32=1) endif() -if(NOT ENABLE_GENERIC) - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86" OR - ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i.86" OR - ${CMAKE_SYSTEM_PROCESSOR} MATCHES "amd64" OR - APPLE) - if(_ARCH_64) - set(_M_X86 1) - set(_M_X86_64 1) - add_definitions(-D_M_X86=1 -D_M_X86_64=1 -msse2) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") - else() - message(FATAL_ERROR "x86_32 is an unsupported platform. Enable generic build if you really want a JIT-less binary.") - endif() - elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm") - message(FATAL_ERROR "ARMv7 is an unsupported platform. Enable generic build if you really want a JIT-less binary.") - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") - # This option only applies to 64bit ARM - set(_M_ARM 1) - set(_M_ARM_64 1) - add_definitions(-D_M_ARM=1 -D_M_ARM_64=1) - add_definitions(-march=armv8-a+crc) - else() - set(ENABLE_GENERIC 1) - endif() -endif() if(ENABLE_GENERIC) message("Warning! Building generic build!") set(_M_GENERIC 1) add_definitions(-D_M_GENERIC=1) +elseif(_ARCH_64 AND ( + ${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86" OR + ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i.86" OR + ${CMAKE_SYSTEM_PROCESSOR} MATCHES "amd64" OR + APPLE +)) + set(_M_X86 1) + set(_M_X86_64 1) + add_definitions(-D_M_X86=1 -D_M_X86_64=1 -msse2) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") +elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") + set(_M_ARM 1) + set(_M_ARM_64 1) + add_definitions(-D_M_ARM=1 -D_M_ARM_64=1) + add_definitions(-march=armv8-a+crc) +else() + message(FATAL_ERROR "You're building on an unsupported platform. Enable generic build if you really want a JIT-less binary.") endif() include(CheckCXXCompilerFlag) @@ -423,6 +415,8 @@ if(ANDROID) # We are cross compiling, search only the toolchain for libraries and includes SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) + SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) elseif(NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES OpenBSD) list(APPEND LIBS rt) endif() diff --git a/Readme.md b/Readme.md index bd6c6285ca..a47d276b04 100644 --- a/Readme.md +++ b/Readme.md @@ -99,29 +99,7 @@ If using Android Studio, import the Gradle project located in `./Source/Android` Android apps are compiled using a build system called Gradle. Dolphin's native component, however, is compiled using CMake. The Gradle script will attempt to run a CMake build -automatically while building the Java code, if you create the file `Source/Android/build.properties`, -and place the following inside: - -``` -# Specifies arguments for the 'make' command. Can be blank. -makeArgs= - -# The path to your machine's Git executable. Will autodetect if blank (on Linux only). -gitPath= - -# The path to the CMake executable. Will autodetect if blank (on Linux only). -cmakePath= - -# The path to the extracted NDK package. Will autodetect if blank (on Linux only). -ndkPath= -``` - -If you prefer, you can run the CMake step manually, and it will copy the resulting -binary into the correct location for inclusion in the Android APK. - -Execute the Gradle task `assembleArm_64Debug` to build, or `installArm_64Debug` to -install the application onto a connected device. If other ABIs are eventually supported, -execute the tasks corresponding to the desired ABI. +automatically while building the Java code. ## Uninstalling When Dolphin has been installed with the NSIS installer, you can uninstall diff --git a/Source/Android/app/.gitignore b/Source/Android/app/.gitignore index 796b96d1c4..0886f94956 100644 --- a/Source/Android/app/.gitignore +++ b/Source/Android/app/.gitignore @@ -1 +1,2 @@ /build +/.externalNativeBuild diff --git a/Source/Android/app/build.gradle b/Source/Android/app/build.gradle index 3cdbade125..f82df2b1d5 100644 --- a/Source/Android/app/build.gradle +++ b/Source/Android/app/build.gradle @@ -2,8 +2,8 @@ apply plugin: 'com.android.application' android { // Leanback support requires >22 - compileSdkVersion 23 - buildToolsVersion '23.0.2' + compileSdkVersion 24 + buildToolsVersion '24.0.3' lintOptions { // This is important as it will run lint but not abort on error @@ -53,213 +53,40 @@ android { applicationIdSuffix ".debug" versionNameSuffix '-debug' jniDebuggable true - - tasks.withType(JavaCompile) { - compileTask -> compileTask.dependsOn(compileNative) - } } } - // Define product flavors, which can be split into categories. Common examples - // of product flavors are paid vs. free, ARM vs. x86, etc. - productFlavors { - arm_64 { - dimension "abi" - ndk { - abiFilter "arm64-v8a" - } + externalNativeBuild { + cmake { + path "../../../CMakeLists.txt" } + } - x86_64 { - dimension "abi" - ndk { - abiFilter "x86_64" + defaultConfig { + externalNativeBuild { + cmake { + arguments "-DANDROID_STL=c++_static", "-DCMAKE_BUILD_TYPE=RelWithDebInfo", "-DENABLE_PCH=OFF" // , "-DENABLE_GENERIC=ON" + abiFilters "arm64-v8a" //, "armeabi-v7a", "x86_64", "x86" } } } } dependencies { - compile 'com.android.support:support-v13:23.1.1' - compile 'com.android.support:cardview-v7:23.1.1' - compile 'com.android.support:recyclerview-v7:23.1.1' - compile 'com.android.support:design:23.1.1' + compile 'com.android.support:support-v13:24.2.1' + compile 'com.android.support:cardview-v7:24.2.1' + compile 'com.android.support:recyclerview-v7:24.2.1' + compile 'com.android.support:design:24.2.1' // Android TV UI libraries. - compile 'com.android.support:leanback-v17:23.1.1' + compile 'com.android.support:leanback-v17:24.2.1' // For showing the banner as a circle a-la Material Design Guidelines - compile 'de.hdodenhof:circleimageview:1.2.2' + compile 'de.hdodenhof:circleimageview:2.1.0' // For loading huge screenshots from the disk. compile 'com.squareup.picasso:picasso:2.5.2' // Allows FRP-style asynchronous operations in Android. - compile 'io.reactivex:rxandroid:1.1.0' + compile 'io.reactivex:rxandroid:1.2.1' } - -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)) - - String abi = getAbi() - - mkdir('build/' + abi) - workingDir 'build/' + abi - - executable getExecutablePath("cmake") - - args "-DANDROID=true", - "-DANDROID_NATIVE_API_LEVEL=android-18", - "-DCMAKE_TOOLCHAIN_FILE=../../../android.toolchain.cmake", - "../../../../..", - "-DGIT_EXECUTABLE=" + getExecutablePath("git"), - "-DANDROID_NDK=" + getNdkPath(), - "-DANDROID_TOOLCHAIN_NAME=" + getToolchainName(), - "-DANDROID_ABI=" + 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)) - - String abi = getAbi() - - workingDir 'build/' + abi - - executable 'make' - - if (buildProperties.makeArgs == null || buildProperties.makeArgs.isEmpty()) { - // TODO - } else { - args buildProperties.makeArgs - } - } else { - executable 'echo' - args 'No build.properties found; skipping native build.' - } -} - -String getExecutablePath(String command) { - def propsFile = rootProject.file("build.properties") - def path = null - - if (propsFile.canRead()) { - def buildProperties = new Properties() - buildProperties.load(new FileInputStream(propsFile)) - println buildProperties - path = buildProperties[command + "Path"] - } - - if (path == null || path.isEmpty()) { - try { - def stdout = new ByteArrayOutputStream() - - exec { - commandLine 'which', command - standardOutput = stdout - } - - path = stdout.toString().trim() - } catch (ignored) { - project.logger.error("Gradle error: Couldn't find " + command + " executable.") - } - } - - if (path != null) { - project.logger.quiet("Gradle: Found " + command + " executuable:" + path) - } - - return path -} - -String getNdkPath() { - def propsFile = rootProject.file("build.properties") - def ndkPath = null - - if (propsFile.canRead()) { - def buildProperties = new Properties() - buildProperties.load(new FileInputStream(propsFile)) - ndkPath = buildProperties.ndkPath - } - - if (ndkPath == null || ndkPath.isEmpty()) { - try { - def stdout = new ByteArrayOutputStream() - - exec { - // ndk-build.cmd is a file unique to the root directory of android-ndk-r10e. - commandLine 'locate', 'ndk-build.cmd' - standardOutput = stdout - } - - def ndkCmdPath = stdout.toString() - ndkPath = ndkCmdPath.substring(0, ndkCmdPath.lastIndexOf('/')) - } catch (ignored) { - project.logger.error("Gradle error: Couldn't find NDK.") - } - } - - if (ndkPath != null) { - project.logger.quiet("Gradle: Found Android NDK: " + ndkPath) - } - return ndkPath -} - -String getAbi() { - String taskName = getGradle().startParameter.taskNames[0] - String abi; - - if (taskName == null) { - return "" - } - - project.logger.quiet("Gradle: Build = " + taskName) - - if (taskName.contains("Arm_64")) { - abi = "arm64-v8a" - } else if (taskName.contains("Arm")) { - abi = "armeabi-v7a" - } else if (taskName.contains("X86_64")) { - abi = "x86_64" - } - - project.logger.quiet("Gradle: ABI name: " + abi) - return abi; -} - -String getToolchainName() { - String taskName = getGradle().startParameter.taskNames[0] - String toolchain; - - if (taskName == null) { - return "" - } - - if (taskName.contains("Arm_64")) { - toolchain = "aarch64-linux-android-4.9" - } else if (taskName.contains("Arm")) { - toolchain = "arm-linux-androideabi-4.9" - } else if (taskName.contains("X86_64")) { - toolchain = "x86_64-4.9" - } - - project.logger.quiet("Gradle: ABI name: " + toolchain) - return toolchain; -} \ No newline at end of file diff --git a/Source/Android/app/src/arm_64/res/values/arrays.xml b/Source/Android/app/src/arm_64/res/values/arrays.xml deleted file mode 100644 index fb98aa63da..0000000000 --- a/Source/Android/app/src/arm_64/res/values/arrays.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - @string/interpreter - @string/cached_interpreter - @string/jit_arm64_recompiler - - - 0 - 5 - 4 - - - \ No newline at end of file diff --git a/Source/Android/app/src/arm_64/res/values/strings.xml b/Source/Android/app/src/arm_64/res/values/strings.xml deleted file mode 100644 index c98efb06b6..0000000000 --- a/Source/Android/app/src/arm_64/res/values/strings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - Dolphin ARM64 - \ No newline at end of file diff --git a/Source/Android/app/src/main/res/layout/dialog_game_details.xml b/Source/Android/app/src/main/res/layout/dialog_game_details.xml index ca33e56007..68715f82be 100644 --- a/Source/Android/app/src/main/res/layout/dialog_game_details.xml +++ b/Source/Android/app/src/main/res/layout/dialog_game_details.xml @@ -19,8 +19,8 @@ android:layout_marginLeft="16dp" android:layout_marginTop="24dp" tools:src="@drawable/placeholder_banner" - app:border_color="?android:colorAccent" - app:border_width="2dp" + app:civ_border_color="?android:colorAccent" + app:civ_border_width="2dp" /> @string/interpreter @string/cached_interpreter + @string/jit_arm64_recompiler + 0 5 + 4 + diff --git a/Source/Android/app/src/x86_64/res/values/arrays.xml b/Source/Android/app/src/x86_64/res/values/arrays.xml deleted file mode 100644 index d4c65b9b63..0000000000 --- a/Source/Android/app/src/x86_64/res/values/arrays.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - @string/interpreter - @string/jit64_recompiler - @string/jitil_recompiler - - - 0 - 1 - 2 - - - \ No newline at end of file diff --git a/Source/Android/build.gradle b/Source/Android/build.gradle index f6e9073125..b1932998a1 100644 --- a/Source/Android/build.gradle +++ b/Source/Android/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' + classpath 'com.android.tools.build:gradle:2.2.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/Source/Android/gradle/wrapper/gradle-wrapper.properties b/Source/Android/gradle/wrapper/gradle-wrapper.properties index f1b6529c23..2686c8e47b 100644 --- a/Source/Android/gradle/wrapper/gradle-wrapper.properties +++ b/Source/Android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Jan 16 16:05:03 EST 2016 +#Sat Aug 06 15:24:00 CEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip diff --git a/Source/Android/jni/CMakeLists.txt b/Source/Android/jni/CMakeLists.txt index b8f0cb865e..4c2514e6db 100644 --- a/Source/Android/jni/CMakeLists.txt +++ b/Source/Android/jni/CMakeLists.txt @@ -13,26 +13,8 @@ android ${LIBS} "-Wl,--no-whole-archive" ) -add_custom_command(TARGET ${SHARED_LIB} POST_BUILD - COMMAND mkdir ARGS -p ${CMAKE_SOURCE_DIR}/Source/Android/app/src/main/jniLibs/${ANDROID_NDK_ABI_NAME} -) -add_custom_command(TARGET ${SHARED_LIB} POST_BUILD - COMMAND mkdir ARGS -p ${CMAKE_SOURCE_DIR}/Source/Android/app/src/main/assets/ -) -add_custom_command(TARGET ${SHARED_LIB} POST_BUILD - COMMAND cp ARGS ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/lib${SHARED_LIB}.so ${CMAKE_SOURCE_DIR}/Source/Android/app/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/ -) -add_custom_command(TARGET ${SHARED_LIB} POST_BUILD - COMMAND ${CMAKE_STRIP} ${CMAKE_SOURCE_DIR}/Source/Android/app/src/main/jniLibs/${ANDROID_NDK_ABI_NAME}/lib${SHARED_LIB}.so -) -add_custom_command(TARGET ${SHARED_LIB} POST_BUILD - COMMAND cp ARGS -r ${CMAKE_SOURCE_DIR}/Data/Sys/GC ${CMAKE_SOURCE_DIR}/Source/Android/app/src/main/assets/ -) -add_custom_command(TARGET ${SHARED_LIB} POST_BUILD - COMMAND cp ARGS -r ${CMAKE_SOURCE_DIR}/Data/Sys/Wii ${CMAKE_SOURCE_DIR}/Source/Android/app/src/main/assets/ -) -add_custom_command(TARGET ${SHARED_LIB} POST_BUILD - COMMAND cp ARGS -r ${CMAKE_SOURCE_DIR}/Data/Sys/Shaders ${CMAKE_SOURCE_DIR}/Source/Android/app/src/main/assets/ -) + +file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Android/app/src/main/assets/) +file(COPY ${CMAKE_SOURCE_DIR}/Data/Sys/GameSettings ${CMAKE_SOURCE_DIR}/Data/Sys/GC ${CMAKE_SOURCE_DIR}/Data/Sys/Wii ${CMAKE_SOURCE_DIR}/Data/Sys/Shaders DESTINATION ${CMAKE_SOURCE_DIR}/Source/Android/app/src/main/assets/) set(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_EXECUTABLES} ${SHARED_LIB}) diff --git a/Source/UnitTests/CMakeLists.txt b/Source/UnitTests/CMakeLists.txt index 479d96c88e..ade9345a00 100644 --- a/Source/UnitTests/CMakeLists.txt +++ b/Source/UnitTests/CMakeLists.txt @@ -5,6 +5,7 @@ endif() if(ANDROID) set(LIBS ${LIBS} android log) endif() +file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Tests) macro(add_dolphin_test target srcs) # Since this is a Core dependency, it can't be linked as a library and has # to be linked as an object file. Otherwise CMake inserts the library after @@ -13,9 +14,6 @@ macro(add_dolphin_test target srcs) set(srcs2 ${srcs} ${CMAKE_SOURCE_DIR}/Source/UnitTests/TestUtils/StubHost.cpp) add_executable(Test_${target} EXCLUDE_FROM_ALL ${srcs2}) set_target_properties(Test_${target} PROPERTIES OUTPUT_NAME Tests/${target}) - add_custom_command(TARGET Test_${target} - PRE_LINK - COMMAND mkdir -p ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Tests) target_link_libraries(Test_${target} ${LIBS}) add_dependencies(unittests Test_${target}) add_test(NAME ${target} COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Tests/${target})