quick cocos2dx-lua: 项目android打包

之前成功过. 现在自己新项目要打包, 又忘记了. 为了下次再打包方便一些, 特此记录.
目录:

(项目根目录: [projectDir])
---|
   |--myPack.bat
   |--encryptSrc.py
   |--copyApkDirHere.py

(proj.android根目录: [projectDir]/frameworks/runtime-src/proj.android/)
---|
   |--build.gradle
  1. 打包脚本([projectDir]/myPack.bat)
@echo off
python encryptSrc.py
cd frameworks\runtime-src\proj.android
python build_native.py
python build_native.py -a arm64-v8a
call .\gradlew.bat assembleRelease --warning-mode=all

cd ../../../
python copyApkDirHere.py
pause
  1. lua代码加密文件([projectDir]/encryptSrc.py)
import os
import shutil
import platform

print "====> Clear source path\n"
sourcePath = "." + os.sep + "frameworks" + os.sep + "runtime-src" + os.sep +"proj.android" + os.sep+ "app" + os.sep + "build" + os.sep + "outputs" + os.sep + "apk" + os.sep + "release"
if os.path.exists(sourcePath):
   shutil.rmtree(sourcePath)
  1. 复制apk文件到根目录脚本([projectDir]/copyApkDirHere.py)
import os
import shutil
print("start copy apks....")
desPath = "." + os.sep + "apk"
sourcePath = "." + os.sep + "frameworks" + os.sep + "runtime-src" + os.sep +"proj.android" + os.sep+ "app" + os.sep + "build" + os.sep + "outputs" + os.sep + "apk" + os.sep + "release"
if os.path.exists(desPath):
   shutil.rmtree(desPath)

#os.makedirs(desPath)
if os.path.exists(sourcePath):
    print("copytree")
    print(sourcePath)
    print(desPath)
    shutil.copytree(sourcePath, desPath + os.sep)

print("copy apks success!")
  1. 生成jks文件
Build -> Generate Signed Bundle / Apk
勾选Apk -> Next -> 填写jks -> Next
[重要]勾选V1(Jar Signature) -> Finish
  1. android项目 app的build.gradle
apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    signingConfigs {
        config {
            keyAlias 'key0'
            keyPassword '123456'
            storeFile file('D:/source/myproject/jube/keystore/jube.jks')
            storePassword '123456'
        }
    }

    defaultConfig {
        applicationId "com.vector.jube"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        ndk {
            abiFilters "arm64-v8a"
            abiFilters "armeabi-v7a"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    android.applicationVariants.all { variant ->
        variant.outputs.all {
            // variant.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + "")
            outputFileName = "${defaultConfig.applicationId}_${defaultConfig.versionName}_${releaseTime()}.apk"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}


static def releaseTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}

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

build cocos2dx
在proj.android根目录: [projectDir]/frameworks/runtime-src/proj.android/

--32位
python build_native.py
--64位
python build_native.py -a arm64-v8a

(完)

你可能感兴趣的:(quick cocos2dx-lua: 项目android打包)