android studio helloworld(binary二进制方式)打包尝试

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/themagickeyjianan/article/details/87927880

背景:binary打包方式

1) File-->Project Structure-->Modules hello_world libcocos2dx

注意hello_world主工程 依赖于libcocos2dx这个库

 

 

 

2) app下面的build.gradle

26.0.2是自己生成的编译工具版本  22也是自动生成编译sdk版本,可通过File-->Project Structure查看

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "org.cocos2d.helloworld"
        minSdkVersion 10
        targetSdkVersion PROP_TARGET_SDK_VERSION
        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 'cocos2djs'
                    arguments 'NDK_TOOLCHAIN_VERSION=4.9'
                    arguments 'APP_PLATFORM=android-'+PROP_TARGET_SDK_VERSION
                    
                    def module_paths = [project.file("/Applications/CocosCreator_v_1_9_3.app/Contents/Resources/cocos2d-x"),
                                        project.file("/Applications/CocosCreator_v_1_9_3.app/Contents/Resources/cocos2d-x/cocos"),
                                        project.file("/Applications/CocosCreator_v_1_9_3.app/Contents/Resources/cocos2d-x/external")]
                    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                        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"
    }

    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'
                }
            }
        }
    }
}

android.applicationVariants.all { variant ->
    // delete previous files first
    delete "${buildDir}/intermediates/assets/${variant.dirName}"

    variant.mergeAssets.doLast {
        copy {
           from "${buildDir}/../../../../../res"
           into "${buildDir}/intermediates/assets/${variant.dirName}/res"
        }

        copy {
            from "${buildDir}/../../../../../src"
            into "${buildDir}/intermediates/assets/${variant.dirName}/src"
        }

        copy {
            from "${buildDir}/../../../../../main.js"
            from "${buildDir}/../../../../../project.json"
            into "${buildDir}/intermediates/assets/${variant.dirName}"
        }

        copy {
            from "/Applications/CocosCreator_v_1_9_3.app/Contents/Resources/cocos2d-x/cocos/scripting/js-bindings/script"
            into "${buildDir}/intermediates/assets/${variant.dirName}/script"
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(':libcocos2dx')
}

最下面的build.gradle 完全由自己生成

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

dependencies {
}

project.properties 用默认的

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-24

gradle.properties是默认的

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

PROP_TARGET_SDK_VERSION=24
PROP_APP_ABI=armeabi-v7a

RELEASE_STORE_FILE=/Applications/CocosCreator_v_1_9_3.app/Contents/Resources/static/build-templates/native/debug.keystore
RELEASE_STORE_PASSWORD=123456
RELEASE_KEY_ALIAS=debug_keystore
RELEASE_KEY_PASSWORD=123456

3) local.properties 里面的sdk和ndk是取得  .zshrc 下面的

# Add environment variable ANDROID_SDK_ROOT for cocos2d-x  
export ANDROID_SDK_ROOT=/Users/jianan/Library/Android/sdk
export PATH=$ANDROID_SDK_ROOT:$PATH  
export PATH=$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$PATH  

# Add environment variable ANT_ROOT for cocos2d-x  
export ANT_ROOT=/Applications/Cocos/tools/ant/bin/  
export PATH=$ANT_ROOT:$PATH  

# Add environment variable NDK_ROOT for cocos2d-x  
export NDK_ROOT=/Users/jianan/Documents/mac_softwares/android-ndk-r10c
export PATH=$NDK_ROOT:$PATH  

自身内容如下:

sdk.dir=/Users/jianan/Library/Android/sdk
ndk.dir=/Users/jianan/Documents/mac_softwares/android-ndk-r10c

4) settings.gradle是需要改动 

project(':libcocos2dx').projectDir这行是需要自己改动的

include ':libcocos2dx'
project(':libcocos2dx').projectDir = new File(settingsDir, './../../cocos2d-x/cocos/platform/android/libcocos2dx')
include ':hello_world'
project(':hello_world').projectDir = new File(settingsDir, 'app')

cocos2dx这个目录 从1.9.3下面拷贝一份过来即可

5) jni/Android.mk内容如下

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := cocos2djs_shared

LOCAL_MODULE_FILENAME := libcocos2djs

ifeq ($(USE_ARM_MODE),1)
LOCAL_ARM_MODE := arm
endif

LOCAL_SRC_FILES := \
../../../Classes/AppDelegate.cpp \
../../../Classes/jsb_module_register.cpp \
hellojavascript/main.cpp \

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes

ifeq ($(USE_ANY_SDK),1)
LOCAL_SRC_FILES += ../../../Classes/anysdk/SDKManager.cpp \
	../../../Classes/anysdk/jsb_anysdk_basic_conversions.cpp \
	../../../Classes/anysdk/manualanysdkbindings.cpp \
	../../../Classes/anysdk/jsb_anysdk_protocols_auto.cpp

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../Classes/anysdk

LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic
endif


LOCAL_STATIC_LIBRARIES := cocos2d_js_static

include $(BUILD_SHARED_LIBRARY)


$(call import-module,scripting/js-bindings/proj.android/prebuilt-mk)

 

Application.mk用默认的

APP_STL := gnustl_static

# Uncomment this line to compile to armeabi-v7a, your application will run faster but support less devices
APP_ABI := armeabi-v7a

APP_CPPFLAGS := -frtti -std=c++11 -fsigned-char
APP_LDFLAGS := -latomic

# To solve windows commands char length too long
#APP_SHORT_COMMANDS := true

USE_ARM_MODE := 1
#USE_ANY_SDK := 1

ifeq ($(USE_ANY_SDK),1)
APP_CPPFLAGS += -DPACKAGE_AS
endif

ifeq ($(NDK_DEBUG),1)
  APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
  APP_CFLAGS += -DCOCOS2D_DEBUG=1
  APP_OPTIM := debug
else
  APP_CPPFLAGS += -DNDEBUG
  APP_CFLAGS += -DNDEBUG
  APP_OPTIM := release
endif

# Some Android Simulators don't support SSE instruction, so disable it for x86 arch.
APP_CPPFLAGS += -U__SSE__

猜你喜欢

转载自blog.csdn.net/themagickeyjianan/article/details/87927880