老版cocos2dx 配置Android Studio 的痛苦回忆
- 完整配置
- proj.android-studio/build.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }
allprojects { repositories { jcenter() google() } }
|
- proj.android-studio/gradle.properties
1 2
| PROP_TARGET_SDK_VERSION=14 PROP_APP_ABI=armeabi-v7a
|
- proj.android-studio/gradle/wrapper/gradle-wrapper.properties
1 2 3 4 5
| distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
|
- proj.android-studio/app/build.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android { compileSdkVersion 24 buildToolsVersion "26.0.2"
defaultConfig { applicationId "com.game.xxx" minSdkVersion 10 targetSdkVersion 23 versionCode 1 versionName "1.0"
externalNativeBuild { ndkBuild { if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { // skip the NDK Build step if PROP_NDK_MODE is none targets 'cocos2dcpp' arguments 'NDK_TOOLCHAIN_VERSION=4.9' arguments 'APP_PLATFORM=android-'+PROP_TARGET_SDK_VERSION
def module_paths = [project.file("../../cocos2d").absolutePath, project.file("../../cocos2d/cocos").absolutePath, project.file("../../cocos2d/external").absolutePath] if (Os.isFamily(Os.FAMILY_WINDOWS)) { // should use '/' module_paths = module_paths.collect {it.replaceAll('\\\\', '/')} arguments 'NDK_MODULE_PATH=' + module_paths.join(";") } else { arguments 'NDK_MODULE_PATH=' + module_paths.join(':') }
arguments '-j' + Runtime.runtime.availableProcessors() abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String}) } } } }
sourceSets.main { java.srcDir "src" res.srcDir "res" jniLibs.srcDir "libs" manifest.srcFile "AndroidManifest.xml" assets.srcDir "../../Resources" }
externalNativeBuild { ndkBuild { if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { // skip the NDK Build step if PROP_NDK_MODE is none path "jni/Android.mk" } } }
signingConfigs {
release { if (project.hasProperty("RELEASE_STORE_FILE")) { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } }
buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' if (project.hasProperty("RELEASE_STORE_FILE")) { signingConfig signingConfigs.release }
externalNativeBuild { ndkBuild { arguments 'NDK_DEBUG=0' } } }
debug { externalNativeBuild { ndkBuild { arguments 'NDK_DEBUG=1' } } } } }
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':libcocos2dx') }
|
- proj.android-studio/app/jni/Android.mk
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d) $(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/external) $(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos) $(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos/audio/include)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
define walk $(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e))) endef
define uniq $(eval seen :=) $(foreach _,$(1),$(if $(filter ${_},${seen}),,$(eval seen += ${_}))) ${seen} endef
ALLFILES = $(call walk, $(LOCAL_PATH)/../../../Classes)
FILE_LIST := $(filter %.cpp, $(ALLFILES)) #FILE_LIST += $(filter %.c, $(ALLFILES)) LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)\ LOCAL_SRC_FILES += ../../../Classes/Libs/SQLite/sqlite3secure.c #LOCAL_SRC_FILES += $(LOCAL_PATH)/hellocpp/main.cpp $(info "UI path2:"$(LOCAL_SRC_FILES))
FILES_PATH := $(LOCAL_PATH)/../../../Classes FILE_INCLUDES := $(dir $(foreach src_path,$(FILES_PATH), $(call walk,$(src_path),*/) ) ) FILE_INCLUDES := $(call uniq,$(FILE_INCLUDES))
LOCAL_C_INCLUDES := $(FILE_INCLUDES)
# _COCOS_HEADER_ANDROID_BEGIN # _COCOS_HEADER_ANDROID_END
LOCAL_STATIC_LIBRARIES := cocos2dx_static
# _COCOS_LIB_ANDROID_BEGIN # _COCOS_LIB_ANDROID_END
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
# _COCOS_LIB_IMPORT_ANDROID_BEGIN # _COCOS_LIB_IMPORT_ANDROID_END
|
- proj.android-studio/app/jni/Application.mk
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char APP_LDFLAGS := -latomic
APP_SHORT_COMMANDS := true APP_CPPFLAGS += -Wno-error=format-security
ifeq ($(NDK_DEBUG),1) APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 APP_OPTIM := debug else APP_CPPFLAGS += -DNDEBUG APP_OPTIM := release endif
|
- cocos2d/cocos/platform/android/libcocos2dx/build.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| apply plugin: 'com.android.library'
android { compileSdkVersion 24 buildToolsVersion "26.0.2"
defaultConfig { minSdkVersion 10 targetSdkVersion 24 versionCode 1 versionName "1.0" }
sourceSets.main { aidl.srcDir "../java/src" java.srcDir "../java/src" manifest.srcFile "AndroidManifest.xml" }
buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) }
|
- 错误汇总
- error: format not a string literal and no format arguments [-Werror=format-security]
ndk目录下修改build/core/default-build-commands.mk
1
| TARGET_FORMAT_STRING_CFLAGS := -Wformat -Werror=format-security
|
为
1
| TARGET_FORMAT_STRING_CFLAGS := -Wformat #-Werror=format-security
|
在Application.mk里面添加下面代码
1
| APP_CPPFLAGS += -Wno-error=format-security
|
但是这个修改后,报运行错误 !
最后通过修改代码
1 2 3 4 5
| 把env->GetStringUTFChars(name_,0);
改成:
Env->GetStringUTFChars(name_NULL);
|
- error: process_begin: CreateProcess(…) make (e=87): 参数错误
原因是.MK文件中包含的文件太多了,而windows对于函数参数个数有限制
在Application.mk文件中添加:
1
| APP_SHORT_COMMANDS := true
|
- ‘malloc’ was not declared in this scope
解决方法:
- invalid conversion from ‘void‘ to ‘char‘
在malloc函数前面加上强转类型(char *)
- Android NDK: INTERNAL ERROR: The armeabi ABI should have exactly one architecture definitions. Found:
原因:
Error:ABIs [armeabi] are not supported for platform. Supported ABIs are [armeabi-v7a, arm64-v8a, x86, x86_64].
gradle.properties配置文件里:
改为
1
| PROP_APP_ABI=armeabi-v7a
|
- Error:Unsupported method: BaseConfig.getApplicationIdSuffix(). The version o
查看app下面的gradle 查看dependencies,看看gradle是不是很低的版本,改成一个自己运行好的项目的gradle即可
1 2
| dependencies { classpath 'com.android.tools.build:gradle:2.3.3'
|