From d084d9f61ad48edf3e8be4f304ac51d7c90e6697 Mon Sep 17 00:00:00 2001 From: halx99 Date: Mon, 17 Aug 2020 18:45:14 +0800 Subject: [PATCH] Improve shared library for android, remove mojoal,sdl2, still use OpenAL.framework on apple platform, alsoft on other platforms. --- cocos/CMakeLists.txt | 25 ------------------- templates/cpp-template-default/CMakeLists.txt | 2 ++ .../app/src/org/cocos2dx/cpp/AppActivity.java | 6 ++++- .../proj.android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- templates/lua-template-default/CMakeLists.txt | 2 ++ .../app/src/org/cocos2dx/lua/AppActivity.java | 5 ++++ .../runtime-src/proj.android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- tests/cpp-tests/CMakeLists.txt | 4 +-- .../org/cocos2dx/cpp_tests/AppActivity.java | 8 +++--- tests/cpp-tests/proj.android/build.gradle | 2 +- .../cpp-tests/proj.android/gradle.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- tests/fairygui-tests/CMakeLists.txt | 3 +-- .../cocos2dx/fairygui_tests/AppActivity.java | 4 +-- .../fairygui-tests/proj.android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- tests/lua-tests/project/CMakeLists.txt | 3 +-- .../org/cocos2dx/lua_tests/AppActivity.java | 5 ++-- .../project/proj.android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- 22 files changed, 38 insertions(+), 51 deletions(-) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index c0ebb71785..092bd48519 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -35,31 +35,6 @@ set(COCOS_CORE_LIB cocos2d) project(cocos2d_libs) -option(CC_USE_MOJOAL "Use mojoAL for all platforms" OFF) -option(CC_USE_ALSOFT "Use openal-soft on apple platform" OFF) - -# checking MojoAL first -if(CC_USE_MOJOAL) - add_definitions(-DCC_USE_MOJOAL=1) -else() # choose openal-soft or apple openal framework - if(NOT APPLE) - set(CC_USE_ALSOFT ON CACHE BOOL "Use openal-soft on apple platform" FORCE) - else() - set(CC_USE_ALSOFT ${CC_USE_ALSOFT} CACHE BOOL "Use openal-soft on apple platform" FORCE) - endif() - if(CC_USE_ALSOFT) - add_definitions(-DCC_USE_ALSOFT=1) - endif() -endif() - -# store al choice to cache -set(CC_USE_MOJOAL ${CC_USE_MOJOAL} CACHE BOOL "Use mojoAL platform" FORCE) -set(CC_USE_ALSOFT ${CC_USE_ALSOFT} CACHE BOOL "Use OpenAL-soft platform" FORCE) - -# print al backend -message(STATUS "CC_USE_MOJOAL:${CC_USE_MOJOAL}") -message(STATUS "CC_USE_ALSOFT:${CC_USE_ALSOFT}") - include(2d/CMakeLists.txt) include(3d/CMakeLists.txt) include(platform/CMakeLists.txt) diff --git a/templates/cpp-template-default/CMakeLists.txt b/templates/cpp-template-default/CMakeLists.txt index e05f5a6f6e..5e5ccf7670 100644 --- a/templates/cpp-template-default/CMakeLists.txt +++ b/templates/cpp-template-default/CMakeLists.txt @@ -127,6 +127,8 @@ else() add_library(${APP_NAME} SHARED ${all_code_files}) add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos/platform/android ${ENGINE_BINARY_PATH}/cocos/platform) target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive) + + config_android_shared_libs("org.cocos2dx.${APP_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src") endif() target_link_libraries(${APP_NAME} cocos2d) diff --git a/templates/cpp-template-default/proj.android/app/src/org/cocos2dx/cpp/AppActivity.java b/templates/cpp-template-default/proj.android/app/src/org/cocos2dx/cpp/AppActivity.java index 661fe75fda..63ef7dfce4 100644 --- a/templates/cpp-template-default/proj.android/app/src/org/cocos2dx/cpp/AppActivity.java +++ b/templates/cpp-template-default/proj.android/app/src/org/cocos2dx/cpp/AppActivity.java @@ -31,7 +31,11 @@ import android.view.WindowManager; import android.view.WindowManager.LayoutParams; public class AppActivity extends Cocos2dxActivity { - + static { + // DNT remove, some android simulator require explicit load shared libraries, otherwise will crash + SharedLoader.load(); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.setEnableVirtualButton(false); diff --git a/templates/cpp-template-default/proj.android/build.gradle b/templates/cpp-template-default/proj.android/build.gradle index 63697d83ac..b95af2926e 100644 --- a/templates/cpp-template-default/proj.android/build.gradle +++ b/templates/cpp-template-default/proj.android/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0' + classpath 'com.android.tools.build:gradle:4.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/templates/cpp-template-default/proj.android/gradle/wrapper/gradle-wrapper.properties b/templates/cpp-template-default/proj.android/gradle/wrapper/gradle-wrapper.properties index 8e341b7af5..5383071a08 100644 --- a/templates/cpp-template-default/proj.android/gradle/wrapper/gradle-wrapper.properties +++ b/templates/cpp-template-default/proj.android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip diff --git a/templates/lua-template-default/CMakeLists.txt b/templates/lua-template-default/CMakeLists.txt index e7b1ac7e8e..ba776c86ff 100644 --- a/templates/lua-template-default/CMakeLists.txt +++ b/templates/lua-template-default/CMakeLists.txt @@ -119,6 +119,8 @@ else() target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive) add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/proj.android ${ENGINE_BINARY_PATH}/cocos/lua-android) target_link_libraries(${APP_NAME} -Wl,--whole-archive lua_android_spec -Wl,--no-whole-archive) + + config_android_shared_libs("org.cocos2dx.${APP_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src") endif() target_link_libraries(${APP_NAME} luacocos2d) diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.android/app/src/org/cocos2dx/lua/AppActivity.java b/templates/lua-template-default/frameworks/runtime-src/proj.android/app/src/org/cocos2dx/lua/AppActivity.java index de22605386..6ffcbcbab3 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.android/app/src/org/cocos2dx/lua/AppActivity.java +++ b/templates/lua-template-default/frameworks/runtime-src/proj.android/app/src/org/cocos2dx/lua/AppActivity.java @@ -30,6 +30,11 @@ import android.os.Bundle; import org.cocos2dx.lib.Cocos2dxActivity; public class AppActivity extends Cocos2dxActivity{ + static { + // DNT remove, some android simulator require explicit load shared libraries, otherwise will crash + SharedLoader.load(); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.setEnableVirtualButton(false); diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.android/build.gradle b/templates/lua-template-default/frameworks/runtime-src/proj.android/build.gradle index 63697d83ac..b95af2926e 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.android/build.gradle +++ b/templates/lua-template-default/frameworks/runtime-src/proj.android/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0' + classpath 'com.android.tools.build:gradle:4.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.android/gradle/wrapper/gradle-wrapper.properties b/templates/lua-template-default/frameworks/runtime-src/proj.android/gradle/wrapper/gradle-wrapper.properties index 8e341b7af5..5383071a08 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.android/gradle/wrapper/gradle-wrapper.properties +++ b/templates/lua-template-default/frameworks/runtime-src/proj.android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index 5db7d76577..1227493406 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -388,8 +388,8 @@ else() add_library(${APP_NAME} SHARED ${all_code_files}) add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos/platform/android ${ENGINE_BINARY_PATH}/cocos/platform) target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive) - configure_file(${OPENAL_SO_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src/main/jniLibs/${ANDROID_ABI}/${OPENAL_SO_NAME} COPYONLY) - configure_file(${MPG123_SO_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src/main/jniLibs/${ANDROID_ABI}/${MPG123_SO_NAME} COPYONLY) + + config_android_shared_libs("org.cocos2dx.${APP_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src") endif() target_link_libraries(${APP_NAME} cocos2d) diff --git a/tests/cpp-tests/proj.android/app/src/org/cocos2dx/cpp_tests/AppActivity.java b/tests/cpp-tests/proj.android/app/src/org/cocos2dx/cpp_tests/AppActivity.java index 93ea3472ad..93e1db741c 100644 --- a/tests/cpp-tests/proj.android/app/src/org/cocos2dx/cpp_tests/AppActivity.java +++ b/tests/cpp-tests/proj.android/app/src/org/cocos2dx/cpp_tests/AppActivity.java @@ -30,9 +30,10 @@ import org.cocos2dx.lib.Cocos2dxActivity; public class AppActivity extends Cocos2dxActivity { static { - System.loadLibrary("mpg123"); - System.loadLibrary("openal"); + // DNT remove, some android simulator require explicit load shared libraries, otherwise will crash + SharedLoader.load(); } + @Override protected void onCreate(Bundle savedInstanceState) { super.setEnableVirtualButton(false); @@ -46,6 +47,5 @@ public class AppActivity extends Cocos2dxActivity { return; } // DO OTHER INITIALIZATION BELOW - } -} \ No newline at end of file +} diff --git a/tests/cpp-tests/proj.android/build.gradle b/tests/cpp-tests/proj.android/build.gradle index 63697d83ac..b95af2926e 100644 --- a/tests/cpp-tests/proj.android/build.gradle +++ b/tests/cpp-tests/proj.android/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0' + classpath 'com.android.tools.build:gradle:4.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/tests/cpp-tests/proj.android/gradle.properties b/tests/cpp-tests/proj.android/gradle.properties index ebbe920606..bb1bdd6f66 100644 --- a/tests/cpp-tests/proj.android/gradle.properties +++ b/tests/cpp-tests/proj.android/gradle.properties @@ -31,7 +31,7 @@ PROP_TARGET_SDK_VERSION=28 # Available architextures (armeabi-v7a | arm64-v8a | x86) # To build for multiple architexture, use the `:` between them # Example - PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86 -PROP_APP_ABI=armeabi-v7a +PROP_APP_ABI=arm64-v8a # uncomment it and fill in sign information for release mode #RELEASE_STORE_FILE=file path of keystore diff --git a/tests/cpp-tests/proj.android/gradle/wrapper/gradle-wrapper.properties b/tests/cpp-tests/proj.android/gradle/wrapper/gradle-wrapper.properties index e743e60d3a..d91e112695 100644 --- a/tests/cpp-tests/proj.android/gradle/wrapper/gradle-wrapper.properties +++ b/tests/cpp-tests/proj.android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip diff --git a/tests/fairygui-tests/CMakeLists.txt b/tests/fairygui-tests/CMakeLists.txt index 2a626362ae..200c220264 100644 --- a/tests/fairygui-tests/CMakeLists.txt +++ b/tests/fairygui-tests/CMakeLists.txt @@ -114,8 +114,7 @@ else() add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos/platform/android ${ENGINE_BINARY_PATH}/cocos/platform) target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive) - configure_file(${OPENAL_SO_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src/main/jniLibs/${ANDROID_ABI}/${OPENAL_SO_NAME} COPYONLY) - configure_file(${MPG123_SO_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src/main/jniLibs/${ANDROID_ABI}/${MPG123_SO_NAME} COPYONLY) + config_android_shared_libs("org.cocos2dx.${APP_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src") endif() target_link_libraries(${APP_NAME} cocos2d) diff --git a/tests/fairygui-tests/proj.android/app/src/org/cocos2dx/fairygui_tests/AppActivity.java b/tests/fairygui-tests/proj.android/app/src/org/cocos2dx/fairygui_tests/AppActivity.java index 3088eb795f..a895cdbdeb 100644 --- a/tests/fairygui-tests/proj.android/app/src/org/cocos2dx/fairygui_tests/AppActivity.java +++ b/tests/fairygui-tests/proj.android/app/src/org/cocos2dx/fairygui_tests/AppActivity.java @@ -30,9 +30,9 @@ import org.cocos2dx.lib.Cocos2dxActivity; public class AppActivity extends Cocos2dxActivity { static { - System.loadLibrary("mpg123"); - System.loadLibrary("openal"); + SharedLoader.load(); } + @Override protected void onCreate(Bundle savedInstanceState) { super.setEnableVirtualButton(false); diff --git a/tests/fairygui-tests/proj.android/build.gradle b/tests/fairygui-tests/proj.android/build.gradle index 63697d83ac..b95af2926e 100644 --- a/tests/fairygui-tests/proj.android/build.gradle +++ b/tests/fairygui-tests/proj.android/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0' + classpath 'com.android.tools.build:gradle:4.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/tests/fairygui-tests/proj.android/gradle/wrapper/gradle-wrapper.properties b/tests/fairygui-tests/proj.android/gradle/wrapper/gradle-wrapper.properties index 70ce2c656e..6f8e4be366 100644 --- a/tests/fairygui-tests/proj.android/gradle/wrapper/gradle-wrapper.properties +++ b/tests/fairygui-tests/proj.android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip \ No newline at end of file +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip \ No newline at end of file diff --git a/tests/lua-tests/project/CMakeLists.txt b/tests/lua-tests/project/CMakeLists.txt index 0515f86f6a..5b755e9537 100644 --- a/tests/lua-tests/project/CMakeLists.txt +++ b/tests/lua-tests/project/CMakeLists.txt @@ -111,8 +111,7 @@ else() target_link_libraries(${APP_NAME} -Wl,--whole-archive lua_android_spec -Wl,--no-whole-archive) endif() - configure_file(${OPENAL_SO_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src/main/jniLibs/${ANDROID_ABI}/${OPENAL_SO_NAME} COPYONLY) - configure_file(${MPG123_SO_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src/main/jniLibs/${ANDROID_ABI}/${MPG123_SO_NAME} COPYONLY) + config_android_shared_libs("org.cocos2dx.${APP_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src") endif() target_link_libraries(${APP_NAME} luacocos2d) target_include_directories(${APP_NAME} PRIVATE Classes) diff --git a/tests/lua-tests/project/proj.android/app/src/org/cocos2dx/lua_tests/AppActivity.java b/tests/lua-tests/project/proj.android/app/src/org/cocos2dx/lua_tests/AppActivity.java index 4358d2da8c..ca32f878b0 100644 --- a/tests/lua-tests/project/proj.android/app/src/org/cocos2dx/lua_tests/AppActivity.java +++ b/tests/lua-tests/project/proj.android/app/src/org/cocos2dx/lua_tests/AppActivity.java @@ -31,9 +31,10 @@ import org.cocos2dx.lib.Cocos2dxGLSurfaceView; public class AppActivity extends Cocos2dxActivity{ static { - System.loadLibrary("mpg123"); - System.loadLibrary("openal"); + // DNT remove, some android simulator require explicit load shared libraries, otherwise will crash + SharedLoader.load(); } + @Override protected void onCreate(Bundle savedInstanceState) { super.setEnableVirtualButton(false); diff --git a/tests/lua-tests/project/proj.android/build.gradle b/tests/lua-tests/project/proj.android/build.gradle index 63697d83ac..b95af2926e 100644 --- a/tests/lua-tests/project/proj.android/build.gradle +++ b/tests/lua-tests/project/proj.android/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0' + classpath 'com.android.tools.build:gradle:4.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/tests/lua-tests/project/proj.android/gradle/wrapper/gradle-wrapper.properties b/tests/lua-tests/project/proj.android/gradle/wrapper/gradle-wrapper.properties index eb512f24e3..63348fc6a5 100644 --- a/tests/lua-tests/project/proj.android/gradle/wrapper/gradle-wrapper.properties +++ b/tests/lua-tests/project/proj.android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip