Skip to content

Commit

Permalink
Updating Minimalist sample to CMake
Browse files Browse the repository at this point in the history
Change-Id: I5f93f743ab77002f4149910d5ace47e0d37cca9f
  • Loading branch information
claywilkinson committed Jan 2, 2018
1 parent bc56515 commit 1a6e96e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 61 deletions.
48 changes: 48 additions & 0 deletions samples-android/Minimalist/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (C) 2017 Google Inc.
#
# 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.
##

cmake_minimum_required(VERSION 3.4.1)

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)

# 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")

add_library(native-activity
SHARED
src/main/jni/main.cpp
src/main/jni/StateManager.cpp
)

target_include_directories(native-activity PRIVATE
${ANDROID_NDK}/sources/android/native_app_glue
${GPG_SDK_PATH}/include
)

target_link_libraries(native-activity
gpg_sdk
native_app_glue
log
android
EGL
GLESv1_CM
z)
59 changes: 32 additions & 27 deletions samples-android/Minimalist/build.gradle
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
/*
* 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.
*/
apply plugin: 'com.android.application'

// 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]

}
}

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

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

ndk {
abiFilters 'x86', 'armeabi-v7a'
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -Wall -frtti"
arguments "-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
"-DANDROID_STL=c++_static"
}
}
}

externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
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 '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'
}
29 changes: 5 additions & 24 deletions samples-android/Minimalist/src/main/jni/StateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,11 @@

#include "StateManager.h"

#ifdef __APPLE__
// Logging for CoreFoundation
#include <CoreFoundation/CoreFoundation.h>

extern "C" void NSLog(CFStringRef format, ...);
const int32_t BUFFER_SIZE = 256;

// Wrap macro in do/while to ensure ;
#define LOGI(...) do { \
char c[BUFFER_SIZE]; \
snprintf(c, BUFFER_SIZE, __VA_ARGS__); \
CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, c, \
kCFStringEncodingMacRoman); \
NSLog(str); \
CFRelease(str); \
} while (false)

#else

#include "android/log.h"
#define DEBUG_TAG "Minimalist"
#define LOGI(...) \
((void)__android_log_print(ANDROID_LOG_INFO, DEBUG_TAG, __VA_ARGS__))

#endif

#include "gpg/achievement_manager.h"
bool StateManager::is_auth_in_progress_ = false;
std::unique_ptr<gpg::GameServices> StateManager::game_services_;
Expand Down Expand Up @@ -117,7 +96,7 @@ void StateManager::InitServices(
if (!game_services_) {
LOGI("Uninitialized services, so creating");
game_services_ = gpg::GameServices::Builder()
.SetLogging(gpg::DEFAULT_ON_LOG, gpg::LogLevel::VERBOSE)
.SetOnLog(gpg::DEFAULT_ON_LOG, gpg::LogLevel::VERBOSE)
.SetOnAuthActionStarted([started_callback](gpg::AuthOperation op) {
is_auth_in_progress_ = true;
if (started_callback != nullptr)
Expand All @@ -138,8 +117,10 @@ void StateManager::InitServices(
LOGI("--------------------------------------------------------------");

LOGI("Fetching all nonblocking");
game_services_->Achievements().FetchAll(gpg::DataSource::CACHE_OR_NETWORK, [] (gpg::AchievementManager::FetchAllResponse response) {LOGI("Achievement response status: %d", response.status);});
LOGI("--------------------------------------------------------------");
game_services_->Achievements().FetchAll(gpg::DataSource::CACHE_OR_NETWORK,
[] (gpg::AchievementManager::FetchAllResponse response) {
LOGI("Achievement response status: %d", response.status);});
LOGI("--------------------------------------------------------------");

})
.Create(pc);
Expand Down
4 changes: 0 additions & 4 deletions samples-android/Minimalist/src/main/jni/StateManager.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef TEAPOT_JNI_STATE_MANAGER_H
#define TEAPOT_JNI_STATE_MANAGER_H

#ifdef __OBJC__
#include <objc/NSObjCRuntime.h>
#endif

#include "gpg/achievement.h"
#include "gpg/achievement_manager.h"
#include "gpg/builder.h"
Expand Down
6 changes: 0 additions & 6 deletions samples-android/Minimalist/src/main/jni/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

// BEGIN_INCLUDE(all)
#include <jni.h>
#include <errno.h>

#include <EGL/egl.h>
#include <GLES/gl.h>
Expand Down Expand Up @@ -264,8 +263,6 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
*/
void android_main(struct android_app* state) {
struct engine engine;
// Make sure glue isn't stripped.
app_dummy();

memset(&engine, 0, sizeof(engine));
state->userData = &engine;
Expand Down Expand Up @@ -336,9 +333,6 @@ void android_main(struct android_app* state) {
ASensorEvent event;
while (ASensorEventQueue_getEvents(engine.sensorEventQueue, &event,
1) > 0) {
/* LOGI("accelerometer: x=%f y=%f z=%f",
event.acceleration.x, event.acceleration.y,
event.acceleration.z); */
}
}
}
Expand Down

0 comments on commit 1a6e96e

Please sign in to comment.