android studio cocos2dx 图片,老版cocos2dx 配置Android Studio 的痛苦回忆

这篇博客详细记录了作者在使用老版Cocos2d-x与Android Studio集成过程中遇到的各种问题,包括Gradle配置、错误修复、文件路径设置等。在解决诸如错误警告、函数参数限制、ABI不匹配、内存分配未声明等问题时,作者提供了具体的修改建议和步骤。最终,作者成功地完成了项目配置,并分享了整个过程中的经验和教训。
摘要由CSDN通过智能技术生成

老版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

2PROP_TARGET_SDK_VERSION=14

PROP_APP_ABI=armeabi-v7a

proj.android-studio/gradle/wrapper/gradle-wrapper.properties

1

2

3

4

5distributionBase=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

100import 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

53LOCAL_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

15APP_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

30apply 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

1TARGET_FORMAT_STRING_CFLAGS := -Wformat -Werror=format-security

1TARGET_FORMAT_STRING_CFLAGS := -Wformat #-Werror=format-security

在Application.mk里面添加下面代码

1APP_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文件中添加:

1APP_SHORT_COMMANDS := true

‘malloc’ was not declared in this scope

解决方法:

1#include

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配置文件里:

1PROP_APP_ABI=armeabi

改为

1PROP_APP_ABI=armeabi-v7a

Error:Unsupported method: BaseConfig.getApplicationIdSuffix(). The version o

查看app下面的gradle 查看dependencies,看看gradle是不是很低的版本,改成一个自己运行好的项目的gradle即可

1

2dependencies {

classpath 'com.android.tools.build:gradle:2.3.3'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值