diff --git a/samples-android/Minimalist/CMakeLists.txt b/samples-android/Minimalist/CMakeLists.txt new file mode 100644 index 0000000..4173286 --- /dev/null +++ b/samples-android/Minimalist/CMakeLists.txt @@ -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) diff --git a/samples-android/Minimalist/build.gradle b/samples-android/Minimalist/build.gradle index 924e125..02029bc 100644 --- a/samples-android/Minimalist/build.gradle +++ b/samples-android/Minimalist/build.gradle @@ -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' } diff --git a/samples-android/Minimalist/src/main/jni/StateManager.cpp b/samples-android/Minimalist/src/main/jni/StateManager.cpp index da63d97..6eda8c4 100644 --- a/samples-android/Minimalist/src/main/jni/StateManager.cpp +++ b/samples-android/Minimalist/src/main/jni/StateManager.cpp @@ -15,32 +15,11 @@ #include "StateManager.h" -#ifdef __APPLE__ -// Logging for CoreFoundation -#include - -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 StateManager::game_services_; @@ -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) @@ -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); diff --git a/samples-android/Minimalist/src/main/jni/StateManager.h b/samples-android/Minimalist/src/main/jni/StateManager.h index 0ac2bb2..d9586c6 100644 --- a/samples-android/Minimalist/src/main/jni/StateManager.h +++ b/samples-android/Minimalist/src/main/jni/StateManager.h @@ -1,10 +1,6 @@ #ifndef TEAPOT_JNI_STATE_MANAGER_H #define TEAPOT_JNI_STATE_MANAGER_H -#ifdef __OBJC__ -#include -#endif - #include "gpg/achievement.h" #include "gpg/achievement_manager.h" #include "gpg/builder.h" diff --git a/samples-android/Minimalist/src/main/jni/main.cpp b/samples-android/Minimalist/src/main/jni/main.cpp index ddd6f88..198f82a 100644 --- a/samples-android/Minimalist/src/main/jni/main.cpp +++ b/samples-android/Minimalist/src/main/jni/main.cpp @@ -33,7 +33,6 @@ // BEGIN_INCLUDE(all) #include -#include #include #include @@ -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; @@ -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); */ } } }