Skip to content

Commit

Permalink
Updating samples to use new GPG SDK and conver to CMake.
Browse files Browse the repository at this point in the history
This also refactors the common code to the Common directory for
rendering the Teapot, interacting with the Java UI, and the NDKHelper
classes.

Change-Id: I7b148b81f0491491d0678175dfef0e4553082f05
  • Loading branch information
claywilkinson committed Dec 28, 2017
1 parent dcd4f2f commit bc56515
Show file tree
Hide file tree
Showing 99 changed files with 1,198 additions and 4,612 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ build/

samples-android/Common/gpg-sdk/gpg-cpp-sdk/
samples-android/Common/gpg-sdk/gpg_cpp_sdk.zip

.DS_Store
89 changes: 89 additions & 0 deletions samples-android/ButtonClicker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (C) 2017 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

#include the native part of JUI Helper
add_subdirectory (${JUI_HELPER_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libjuihelper")

#include the native part of NDKHelper
add_subdirectory (${NDK_HELPER_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libndkhelper")

#include the GPG C++ SDK
add_library(gpg_sdk STATIC IMPORTED)
set_target_properties(gpg_sdk PROPERTIES IMPORTED_LOCATION
${GPG_SDK_PATH}/lib/c++/${ANDROID_ABI}/libgpg.a)

# build native_app_glue as a static lib
add_library(native_app_glue STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

# build cpufeatures as a static lib
add_library(cpufeatures STATIC
${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)

# Export ANativeActivity_onCreate(),
# Refer to: https://github.com/android-ndk/ndk/issues/381.
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
ButtonClickerNativeActivity

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
src/main/jni/ButtonClickerNativeActivity.cpp
src/main/jni/ButtonClickerNativeActivity_Engine.cpp
${TEAPOT_RENDERER_PATH}/TeapotRenderer.cpp
)

target_include_directories(ButtonClickerNativeActivity PRIVATE
${ANDROID_NDK}/sources/android/native_app_glue
${ANDROID_NDK}/sources/android/cpufeatures
${GPG_SDK_PATH}/include
${juihelper_SOURCE_DIR}/src/main/cpp
${ndkhelper_SOURCE_DIR}/src/main/cpp
${TEAPOT_RENDERER_PATH}
)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries(ButtonClickerNativeActivity
gpg_sdk
native_app_glue
cpufeatures
juihelper
ndkhelper
log
android
EGL
GLESv2
z
)
73 changes: 42 additions & 31 deletions samples-android/ButtonClicker/build.gradle
Original file line number Diff line number Diff line change
@@ -1,42 +1,53 @@
apply plugin: 'com.android.application'
/*
* Copyright 2017 (C) Google LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Depend on another project that downloads and unzips the C++ SDK.
evaluationDependsOn(':Common/gpg-sdk')

// As the plugin has created the build tasks, add the gpg-sdk task to
// the task dependencies so it gets done before compiling
tasks.whenTaskAdded { task ->
project(':Common/gpg-sdk').defaultTasks.each {
t ->task.dependsOn project(':Common/gpg-sdk').tasks[t]

}
}
apply plugin : 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
//
// REPLACE THE APPLICATION ID with your bundle ID
//
applicationId "com.google.example.games.ReplaceMe"
minSdkVersion 14
targetSdkVersion 23
compileSdkVersion 26
defaultConfig {
//
// REPLACE THE APPLICATION ID with your bundle ID
//
applicationId "com.google.example.games.ReplaceMe"
minSdkVersion 14
targetSdkVersion 26

ndk {
abiFilters 'x86', 'armeabi-v7a'
}
}

ndk.abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a'

externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
cmake {
cppFlags "-std=c++11 -Wall -frtti"
arguments "-DANDROID_STL=c++_static",
"-DJUI_HELPER_PATH=${project(':Common:JuiHelper').projectDir}",
"-DNDK_HELPER_PATH=${project(':Common:NDKHelper').projectDir}",
"-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
"-DTEAPOT_RENDERER_PATH=${project(':Common').projectDir}/TeapotRenderer"
}
}
}

externalNativeBuild {
cmake.path "CMakeLists.txt"
}
}

dependencies {
compile 'com.google.android.gms:play-services-games:10.0.0'
compile 'com.google.android.gms:play-services-nearby:10.0.0'
compile 'com.android.support:support-v4:23.1.1'
implementation project(":Common:JuiHelper")
implementation 'com.google.android.gms:play-services-games:11.6.2'
implementation 'com.google.android.gms:play-services-nearby:11.6.2'
implementation 'com.android.support:support-v4:26.1.0'
}
1 change: 0 additions & 1 deletion samples-android/ButtonClicker/src/main/ant.properties

This file was deleted.

7 changes: 0 additions & 7 deletions samples-android/ButtonClicker/src/main/build.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@

public class ButtonClickerApplication extends Application {
public void onCreate() {
super.onCreate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class ButtonClickerNativeActivity extends NativeActivity {
// Load SO
static {
System.load("libButtonClickerNativeActivity.so");
System.loadLibrary("ButtonClickerNativeActivity");
}

@Override
Expand All @@ -46,7 +46,6 @@ public void onSystemUiVisibilityChange(int visibility) {
}
});
}

nativeOnActivityCreated(this, savedInstanceState);
}

Expand Down
Loading

0 comments on commit bc56515

Please sign in to comment.