Skip to content

Commit 1a6e96e

Browse files
committed
Updating Minimalist sample to CMake
Change-Id: I5f93f743ab77002f4149910d5ace47e0d37cca9f
1 parent bc56515 commit 1a6e96e

File tree

5 files changed

+85
-61
lines changed

5 files changed

+85
-61
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (C) 2017 Google Inc.
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+
cmake_minimum_required(VERSION 3.4.1)
17+
18+
add_library(gpg_sdk STATIC IMPORTED)
19+
set_target_properties(gpg_sdk PROPERTIES IMPORTED_LOCATION
20+
${GPG_SDK_PATH}/lib/c++/${ANDROID_ABI}/libgpg.a)
21+
22+
# build native_app_glue as a static lib
23+
add_library(native_app_glue STATIC
24+
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
25+
26+
# Export ANativeActivity_onCreate()
27+
# Refer to: https://github.com/android-ndk/ndk/issues/381.
28+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
29+
30+
add_library(native-activity
31+
SHARED
32+
src/main/jni/main.cpp
33+
src/main/jni/StateManager.cpp
34+
)
35+
36+
target_include_directories(native-activity PRIVATE
37+
${ANDROID_NDK}/sources/android/native_app_glue
38+
${GPG_SDK_PATH}/include
39+
)
40+
41+
target_link_libraries(native-activity
42+
gpg_sdk
43+
native_app_glue
44+
log
45+
android
46+
EGL
47+
GLESv1_CM
48+
z)
Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
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+
*/
115
apply plugin: 'com.android.application'
216

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-
}
14-
15-
android {
16-
compileSdkVersion 23
17-
buildToolsVersion '23.0.2'
17+
android {
18+
compileSdkVersion 26
1819
defaultConfig {
19-
//
20-
// REPLACE THE APPLICATION ID with your bundle ID
21-
//
20+
//
21+
// REPLACE THE APPLICATION ID with your bundle ID
22+
//
2223
applicationId "com.google.example.games.ReplaceMe"
2324
minSdkVersion 14
24-
targetSdkVersion 23
25+
targetSdkVersion 26
26+
27+
ndk.abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a'
2528

26-
ndk {
27-
abiFilters 'x86', 'armeabi-v7a'
29+
externalNativeBuild {
30+
cmake {
31+
cppFlags "-std=c++11 -Wall -frtti"
32+
arguments "-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
33+
"-DANDROID_STL=c++_static"
34+
}
2835
}
2936
}
3037

3138
externalNativeBuild {
32-
ndkBuild {
33-
path 'src/main/jni/Android.mk'
34-
}
39+
cmake.path "CMakeLists.txt"
3540
}
3641
}
3742

3843
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'
44+
implementation 'com.google.android.gms:play-services-games:11.6.2'
45+
implementation 'com.google.android.gms:play-services-nearby:11.6.2'
46+
implementation 'com.android.support:support-v4:26.1.0'
4247
}

samples-android/Minimalist/src/main/jni/StateManager.cpp

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,11 @@
1515

1616
#include "StateManager.h"
1717

18-
#ifdef __APPLE__
19-
// Logging for CoreFoundation
20-
#include <CoreFoundation/CoreFoundation.h>
21-
22-
extern "C" void NSLog(CFStringRef format, ...);
23-
const int32_t BUFFER_SIZE = 256;
24-
25-
// Wrap macro in do/while to ensure ;
26-
#define LOGI(...) do { \
27-
char c[BUFFER_SIZE]; \
28-
snprintf(c, BUFFER_SIZE, __VA_ARGS__); \
29-
CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, c, \
30-
kCFStringEncodingMacRoman); \
31-
NSLog(str); \
32-
CFRelease(str); \
33-
} while (false)
34-
35-
#else
36-
3718
#include "android/log.h"
3819
#define DEBUG_TAG "Minimalist"
3920
#define LOGI(...) \
4021
((void)__android_log_print(ANDROID_LOG_INFO, DEBUG_TAG, __VA_ARGS__))
4122

42-
#endif
43-
4423
#include "gpg/achievement_manager.h"
4524
bool StateManager::is_auth_in_progress_ = false;
4625
std::unique_ptr<gpg::GameServices> StateManager::game_services_;
@@ -117,7 +96,7 @@ void StateManager::InitServices(
11796
if (!game_services_) {
11897
LOGI("Uninitialized services, so creating");
11998
game_services_ = gpg::GameServices::Builder()
120-
.SetLogging(gpg::DEFAULT_ON_LOG, gpg::LogLevel::VERBOSE)
99+
.SetOnLog(gpg::DEFAULT_ON_LOG, gpg::LogLevel::VERBOSE)
121100
.SetOnAuthActionStarted([started_callback](gpg::AuthOperation op) {
122101
is_auth_in_progress_ = true;
123102
if (started_callback != nullptr)
@@ -138,8 +117,10 @@ void StateManager::InitServices(
138117
LOGI("--------------------------------------------------------------");
139118

140119
LOGI("Fetching all nonblocking");
141-
game_services_->Achievements().FetchAll(gpg::DataSource::CACHE_OR_NETWORK, [] (gpg::AchievementManager::FetchAllResponse response) {LOGI("Achievement response status: %d", response.status);});
142-
LOGI("--------------------------------------------------------------");
120+
game_services_->Achievements().FetchAll(gpg::DataSource::CACHE_OR_NETWORK,
121+
[] (gpg::AchievementManager::FetchAllResponse response) {
122+
LOGI("Achievement response status: %d", response.status);});
123+
LOGI("--------------------------------------------------------------");
143124

144125
})
145126
.Create(pc);

samples-android/Minimalist/src/main/jni/StateManager.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#ifndef TEAPOT_JNI_STATE_MANAGER_H
22
#define TEAPOT_JNI_STATE_MANAGER_H
33

4-
#ifdef __OBJC__
5-
#include <objc/NSObjCRuntime.h>
6-
#endif
7-
84
#include "gpg/achievement.h"
95
#include "gpg/achievement_manager.h"
106
#include "gpg/builder.h"

samples-android/Minimalist/src/main/jni/main.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
// BEGIN_INCLUDE(all)
3535
#include <jni.h>
36-
#include <errno.h>
3736

3837
#include <EGL/egl.h>
3938
#include <GLES/gl.h>
@@ -264,8 +263,6 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
264263
*/
265264
void android_main(struct android_app* state) {
266265
struct engine engine;
267-
// Make sure glue isn't stripped.
268-
app_dummy();
269266

270267
memset(&engine, 0, sizeof(engine));
271268
state->userData = &engine;
@@ -336,9 +333,6 @@ void android_main(struct android_app* state) {
336333
ASensorEvent event;
337334
while (ASensorEventQueue_getEvents(engine.sensorEventQueue, &event,
338335
1) > 0) {
339-
/* LOGI("accelerometer: x=%f y=%f z=%f",
340-
event.acceleration.x, event.acceleration.y,
341-
event.acceleration.z); */
342336
}
343337
}
344338
}

0 commit comments

Comments
 (0)