Skip to content

Commit bc56515

Browse files
committed
Updating samples to use new GPG SDK and conver to CMake.
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
1 parent dcd4f2f commit bc56515

File tree

99 files changed

+1198
-4612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1198
-4612
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ build/
1515

1616
samples-android/Common/gpg-sdk/gpg-cpp-sdk/
1717
samples-android/Common/gpg-sdk/gpg_cpp_sdk.zip
18+
19+
.DS_Store
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright (C) 2017 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
##
15+
16+
# For more information about using CMake with Android Studio, read the
17+
# documentation: https://d.android.com/studio/projects/add-native-code.html
18+
19+
# Sets the minimum version of CMake required to build the native library.
20+
21+
cmake_minimum_required(VERSION 3.4.1)
22+
23+
#include the native part of JUI Helper
24+
add_subdirectory (${JUI_HELPER_PATH}
25+
"${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libjuihelper")
26+
27+
#include the native part of NDKHelper
28+
add_subdirectory (${NDK_HELPER_PATH}
29+
"${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libndkhelper")
30+
31+
#include the GPG C++ SDK
32+
add_library(gpg_sdk STATIC IMPORTED)
33+
set_target_properties(gpg_sdk PROPERTIES IMPORTED_LOCATION
34+
${GPG_SDK_PATH}/lib/c++/${ANDROID_ABI}/libgpg.a)
35+
36+
# build native_app_glue as a static lib
37+
add_library(native_app_glue STATIC
38+
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
39+
40+
# build cpufeatures as a static lib
41+
add_library(cpufeatures STATIC
42+
${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
43+
44+
# Export ANativeActivity_onCreate(),
45+
# Refer to: https://github.com/android-ndk/ndk/issues/381.
46+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
47+
48+
# Creates and names a library, sets it as either STATIC
49+
# or SHARED, and provides the relative paths to its source code.
50+
# You can define multiple libraries, and CMake builds them for you.
51+
# Gradle automatically packages shared libraries with your APK.
52+
53+
add_library( # Sets the name of the library.
54+
ButtonClickerNativeActivity
55+
56+
# Sets the library as a shared library.
57+
SHARED
58+
59+
# Provides a relative path to your source file(s).
60+
src/main/jni/ButtonClickerNativeActivity.cpp
61+
src/main/jni/ButtonClickerNativeActivity_Engine.cpp
62+
${TEAPOT_RENDERER_PATH}/TeapotRenderer.cpp
63+
)
64+
65+
target_include_directories(ButtonClickerNativeActivity PRIVATE
66+
${ANDROID_NDK}/sources/android/native_app_glue
67+
${ANDROID_NDK}/sources/android/cpufeatures
68+
${GPG_SDK_PATH}/include
69+
${juihelper_SOURCE_DIR}/src/main/cpp
70+
${ndkhelper_SOURCE_DIR}/src/main/cpp
71+
${TEAPOT_RENDERER_PATH}
72+
)
73+
74+
# Specifies libraries CMake should link to your target library. You
75+
# can link multiple libraries, such as libraries you define in this
76+
# build script, prebuilt third-party libraries, or system libraries.
77+
78+
target_link_libraries(ButtonClickerNativeActivity
79+
gpg_sdk
80+
native_app_glue
81+
cpufeatures
82+
juihelper
83+
ndkhelper
84+
log
85+
android
86+
EGL
87+
GLESv2
88+
z
89+
)
Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,53 @@
1-
apply plugin: 'com.android.application'
1+
/*
2+
* Copyright 2017 (C) Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
215

3-
// Depend on another project that downloads and unzips the C++ SDK.
4-
evaluationDependsOn(':Common/gpg-sdk')
5-
6-
// As the plugin has created the build tasks, add the gpg-sdk task to
7-
// the task dependencies so it gets done before compiling
8-
tasks.whenTaskAdded { task ->
9-
project(':Common/gpg-sdk').defaultTasks.each {
10-
t ->task.dependsOn project(':Common/gpg-sdk').tasks[t]
11-
12-
}
13-
}
16+
apply plugin : 'com.android.application'
1417

1518
android {
16-
compileSdkVersion 23
17-
buildToolsVersion '23.0.2'
18-
defaultConfig {
19-
//
20-
// REPLACE THE APPLICATION ID with your bundle ID
21-
//
22-
applicationId "com.google.example.games.ReplaceMe"
23-
minSdkVersion 14
24-
targetSdkVersion 23
19+
compileSdkVersion 26
20+
defaultConfig {
21+
//
22+
// REPLACE THE APPLICATION ID with your bundle ID
23+
//
24+
applicationId "com.google.example.games.ReplaceMe"
25+
minSdkVersion 14
26+
targetSdkVersion 26
2527

26-
ndk {
27-
abiFilters 'x86', 'armeabi-v7a'
28-
}
29-
}
28+
29+
ndk.abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a'
3030

3131
externalNativeBuild {
32-
ndkBuild {
33-
path 'src/main/jni/Android.mk'
34-
}
32+
cmake {
33+
cppFlags "-std=c++11 -Wall -frtti"
34+
arguments "-DANDROID_STL=c++_static",
35+
"-DJUI_HELPER_PATH=${project(':Common:JuiHelper').projectDir}",
36+
"-DNDK_HELPER_PATH=${project(':Common:NDKHelper').projectDir}",
37+
"-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
38+
"-DTEAPOT_RENDERER_PATH=${project(':Common').projectDir}/TeapotRenderer"
39+
}
3540
}
41+
}
42+
43+
externalNativeBuild {
44+
cmake.path "CMakeLists.txt"
45+
}
3646
}
3747

3848
dependencies {
39-
compile 'com.google.android.gms:play-services-games:10.0.0'
40-
compile 'com.google.android.gms:play-services-nearby:10.0.0'
41-
compile 'com.android.support:support-v4:23.1.1'
49+
implementation project(":Common:JuiHelper")
50+
implementation 'com.google.android.gms:play-services-games:11.6.2'
51+
implementation 'com.google.android.gms:play-services-nearby:11.6.2'
52+
implementation 'com.android.support:support-v4:26.1.0'
4253
}

samples-android/ButtonClicker/src/main/ant.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

samples-android/ButtonClicker/src/main/build.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

samples-android/ButtonClicker/src/main/java/com/google/example/games/ButtonClicker/ButtonClickerApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020

2121
public class ButtonClickerApplication extends Application {
2222
public void onCreate() {
23+
super.onCreate();
2324
}
2425
}

samples-android/ButtonClicker/src/main/java/com/google/example/games/ButtonClicker/ButtonClickerNativeActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class ButtonClickerNativeActivity extends NativeActivity {
2727
// Load SO
2828
static {
29-
System.load("libButtonClickerNativeActivity.so");
29+
System.loadLibrary("ButtonClickerNativeActivity");
3030
}
3131

3232
@Override
@@ -46,7 +46,6 @@ public void onSystemUiVisibilityChange(int visibility) {
4646
}
4747
});
4848
}
49-
5049
nativeOnActivityCreated(this, savedInstanceState);
5150
}
5251

0 commit comments

Comments
 (0)