gradlew打包Android環(huán)境搭建

cd frameworks\runtime-src\proj.android-studio
gradlew

gradlew命令其實(shí)運(yùn)行的是proj.android-studio目錄下的gradlew.bat腳本

1.安裝Java和下載gradlew

第一次會(huì)提示沒(méi)有java

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Java下載頁(yè)面霜瘪,我選擇的是jdk8,安裝完畢财异,檢查下Java是否正確安裝


重新執(zhí)行g(shù)radlew栅屏,會(huì)下載需要的gradle

2.配置SDK

運(yùn)行失敗朵你,提示

> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

我使用的是android-sdk_r24.4.1-windows

定義local.properties文件,或者定義ANDROID_HOME環(huán)境變量

我選擇增加local.properties文件,需要注意路徑的書(shū)寫(xiě)方式

sdk.dir=D://dev/android-sdk-windows

3.下載項(xiàng)目使用的SDK platform 和 build-tools版本

再次執(zhí)行g(shù)radlew

> You have not accepted the license agreements of the following SDK components:
  [Android SDK Build-Tools 26.0.2, Android SDK Platform 29].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

提示指定版本的sdk的license有問(wèn)題橙数,我選擇了重新安裝來(lái)繞過(guò)了這個(gè)問(wèn)題
運(yùn)行SDK Manager.exe蕉饼,重新安裝下build-toolssdk platform


提示信息和項(xiàng)目配置對(duì)應(yīng)的

4. 配置NDK

再次執(zhí)行g(shù)radlew虐杯,提示ndk沒(méi)有配置

> NDK not configured.
  Download it with SDK manager

查閱資料得知cocos2dx v3.16官方建議使用NDK r14
在local.properties中配置

ndk.dir=D://dev//android-ndk-r14b

再次執(zhí)行,如果發(fā)現(xiàn)報(bào)錯(cuò)NDK中缺少ABI昧港,多半是NDK版本混用導(dǎo)致的

> No toolchains found in the NDK toolchains folder for ABI with prefix: aarch64-linux-android

5.配置libcocos2dx需要的SDK

再次執(zhí)行擎椰,發(fā)現(xiàn)項(xiàng)目可以正常通過(guò),但是libcocos2dx缺少對(duì)應(yīng)的sdk创肥,同步驟3达舒,安裝即可

A problem occurred configuring project ':libcocos2dx'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Platform 14].

再次執(zhí)行g(shù)radlew

如果你看到如下圖所示的build successful值朋,只是說(shuō)明通過(guò)了配置的環(huán)境檢查


gradlew的使用

根據(jù)上一步的提示:

gradlew --help可以查看詳細(xì)的命令參數(shù)

USAGE: gradlew [option...] [task...]

-?, -h, --help          Shows this help message.
-a, --no-rebuild        Do not rebuild project dependencies.
-b, --build-file        Specify the build file.
--build-cache           Enables the Gradle build cache. Gradle will try to reuse outputs from previous builds. [incubating]
-c, --settings-file     Specify the settings file.
--configure-on-demand   Configure necessary projects only. Gradle will attempt to reduce configuration time for large multi-project builds. [incubating]
--console               Specifies which type of console output to generate. Values are 'plain', 'auto' (default) or 'rich'.
--continue              Continue task execution after a task failure.
-D, --system-prop       Set system property of the JVM (e.g. -Dmyprop=myvalue).
-d, --debug             Log in debug mode (includes normal stacktrace).
--daemon                Uses the Gradle Daemon to run the build. Starts the Daemon if not running.
--foreground            Starts the Gradle Daemon in the foreground. [incubating]
-g, --gradle-user-home  Specifies the gradle user home directory.
-I, --init-script       Specify an initialization script.
-i, --info              Set log level to info.
--include-build         Include the specified build in the composite. [incubating]
-m, --dry-run           Run the builds with all task actions disabled.
--max-workers           Configure the number of concurrent workers Gradle is allowed to use. [incubating]
--no-build-cache        Disables the Gradle build cache. [incubating]
--no-daemon             Do not use the Gradle Daemon to run the build.
--no-scan               Disables the creation of a build scan. (https://gradle.com/build-scans) [incubating]
--offline               Execute the build without accessing network resources.
-P, --project-prop      Set project property for the build script (e.g. -Pmyprop=myvalue).
-p, --project-dir       Specifies the start directory for Gradle. Defaults to current directory.
--parallel              Build projects in parallel. Gradle will attempt to determine the optimal number of executor threads to use. [incubating]
--profile               Profile build execution time and generates a report in the <build_dir>/reports/profile directory.
--project-cache-dir     Specify the project-specific cache directory. Defaults to .gradle in the root project directory.-q, --quiet             Log errors only.
--recompile-scripts     Force build script recompiling.
--refresh-dependencies  Refresh the state of dependencies.
--rerun-tasks           Ignore previously cached task results.
-S, --full-stacktrace   Print out the full (very verbose) stacktrace for all exceptions.
-s, --stacktrace        Print out the stacktrace for all exceptions.
--scan                  Creates a build scan. Gradle will emit a warning if the build scan plugin has not been applied. (https://gradle.com/build-scans) [incubating]
--status                Shows status of running and recently stopped Gradle Daemon(s).
--stop                  Stops the Gradle Daemon if it is running.
-t, --continuous        Enables continuous build. Gradle does not exit and will re-execute tasks when task file inputs change. [incubating]
-u, --no-search-upward  Don't search in parent folders for a settings.gradle file.
-v, --version           Print version info.
-w, --warn              Set log level to warn.
-x, --exclude-task      Specify a task to be excluded from execution.

打包

gradlew tasks命令中,我們會(huì)發(fā)現(xiàn)很多task

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Android tasks
-------------
androidDependencies - Displays the Android dependencies of the project.
signingReport - Displays the signing info for each variant.
sourceSets - Prints out all the source sets defined in this project.

Build tasks
-----------
assemble - Assembles all variants of all applications and secondary packages.
assembleAndroidTest - Assembles all the Test applications.
assembleDebug - Assembles all Debug builds.
assembleRelease - Assembles all Release builds.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
clean - Deletes the build directory.
cleanBuildCache - Deletes the build cache directory.
compileDebugAndroidTestSources
compileDebugSources
compileDebugUnitTestSources
compileReleaseSources
compileReleaseUnitTestSources
extractDebugAnnotations - Extracts Android annotations for the debug variant into the archive file
extractReleaseAnnotations - Extracts Android annotations for the release variant into the archive file
mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'proj.android-studio'.
components - Displays the components produced by root project 'proj.android-studio'. [incubating]
dependencies - Displays all dependencies declared in root project 'proj.android-studio'.
dependencyInsight - Displays the insight into a specific dependency in root project 'proj.android-studio'.
dependentComponents - Displays the dependent components of components in root project 'proj.android-studio'. [incubating]
help - Displays a help message.
model - Displays the configuration model of root project 'proj.android-studio'. [incubating]
projects - Displays the sub-projects of root project 'proj.android-studio'.
properties - Displays the properties of root project 'proj.android-studio'.
tasks - Displays the tasks runnable from root project 'proj.android-studio' (some of the displayed tasks may belong to subprojects).

Install tasks
-------------
installDebug - Installs the Debug build.
installDebugAndroidTest - Installs the android (on device) tests for the Debug build.
installRelease - Installs the Release build.
uninstallAll - Uninstall all applications.
uninstallDebug - Uninstalls the Debug build.
uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.
uninstallRelease - Uninstalls the Release build.

Verification tasks
------------------
check - Runs all checks.
connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
connectedCheck - Runs all device checks on currently connected devices.
connectedDebugAndroidTest - Installs and runs the tests for debug on connected devices.
deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers.
deviceCheck - Runs all device checks using Device Providers and Test Servers.
lint - Runs lint on all variants.
lintDebug - Runs lint on the Debug build.
lintRelease - Runs lint on the Release build.
lintVitalRelease - Runs lint on just the fatal issues in the release build.
test - Run unit tests for all variants.
testDebugUnitTest - Run unit tests for the debug build.
testReleaseUnitTest - Run unit tests for the release build.

其中Build Tasks中的build是我們需要的打包命令

gradlew build --build-cache

加快打包速度:

--build-cache           Enables the Gradle build cache. Gradle will try to reuse outputs from previous builds. [incubating]

NDK版本的問(wèn)題: process_begin: CreateProcess failed. make (e=2)

process_begin: CreateProcess(NULL, 
D:/dev/android-ndk-r14b/build//../toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ 
-MMD -MP -MF
.... 我這里做了省略巩搏,這里的報(bào)錯(cuò)超級(jí)超級(jí)長(zhǎng)
 ...) failed.
  make (e=2): ?????????????????

CreateProcess給出的報(bào)錯(cuò)信息中昨登,使用到了ndk的一個(gè)目錄下的文件
ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++
實(shí)際上,我發(fā)現(xiàn)是沒(méi)有這個(gè)文件的


然后我下載了r16b解壓后發(fā)現(xiàn)是有的:

Werror=format-security

切換到r16b后再次進(jìn)行編譯

/frameworks/cocos2d-x/cocos/3d/../platform/CCPlatformMacros.h:221:67: 
error: format not a string literal and no format arguments [-Werror=format-security]
#define CCLOGERROR(format,...)  cocos2d::log(format, ##__VA_ARGS__)
  • 解決辦法1:在app/jni/Android.mk中加入贯底,不對(duì)prinft的參數(shù)進(jìn)行常量字符串檢查

LOCAL_DISABLE_FORMAT_STRING_CHECKS :=true

  • 解決辦法2(未驗(yàn)證):app/jni/Application.mk加入

APP_CFLAGS += -Wno-error=format-security
意思是無(wú)視這個(gè)error

  • 解決辦法3(未驗(yàn)證)
    在CMake腳本文件CMakeLists.txt里面添加一行add_definitions (-Wno-format-security)即可丰辣。
    這種情況實(shí)際是編譯器把warining作為error處理了,遇到其他類(lèi)似情況同樣處理禽捆,報(bào)[-Werror,-WXXX]add_definitions (-Wno-XXX)笙什。

不知原因的問(wèn)題

error: undefined reference to 'vtable
the vtable symbol may be undefined because the class is missing its key function

把構(gòu)造,析構(gòu)的實(shí)現(xiàn)放在cpp里面就解決了

android studio 下載

下載地址
gradle版本對(duì)照表

build.gradle 4.x 需要下載Android Studio3.0

java heap space

gradle.properties修改jvm options即可胚想,堆空間設(shè)置的大一點(diǎn)

# 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
org.gradle.jvmargs=-Xmx4096m

真機(jī)安裝

gradlew installDebug


手機(jī)系統(tǒng)中有應(yīng)用阻止了安裝

小米手機(jī):在手機(jī)的開(kāi)發(fā)者模式中關(guān)閉MIUI優(yōu)化

lint導(dǎo)致打包停止

* What went wrong:
Execution failed for task ':xxxx:lint'.
> Lint found errors in the project; aborting build.

  Fix the issues identified by lint, or add the following to your build script to proceed with errors:
  ...
  android {
      lintOptions {
          abortOnError false
      }
  }
  ...

按照f(shuō)ix提示琐凭,修改build.gradle即可

小結(jié)

類(lèi)似問(wèn)題最好遇到一次記錄一次,防止反復(fù)查閱浊服,很費(fèi)時(shí)間的

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末统屈,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子臼闻,更是在濱河造成了極大的恐慌鸿吆,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,490評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件述呐,死亡現(xiàn)場(chǎng)離奇詭異惩淳,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)乓搬,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,581評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)思犁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人进肯,你說(shuō)我怎么就攤上這事激蹲。” “怎么了江掩?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,830評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵学辱,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我环形,道長(zhǎng)策泣,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,957評(píng)論 1 295
  • 正文 為了忘掉前任抬吟,我火速辦了婚禮萨咕,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘火本。我一直安慰自己危队,他們只是感情好聪建,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,974評(píng)論 6 393
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著茫陆,像睡著了一般金麸。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上盅弛,一...
    開(kāi)封第一講書(shū)人閱讀 51,754評(píng)論 1 307
  • 那天钱骂,我揣著相機(jī)與錄音叔锐,去河邊找鬼挪鹏。 笑死,一個(gè)胖子當(dāng)著我的面吹牛愉烙,可吹牛的內(nèi)容都是我干的讨盒。 我是一名探鬼主播,決...
    沈念sama閱讀 40,464評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼步责,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼返顺!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起蔓肯,我...
    開(kāi)封第一講書(shū)人閱讀 39,357評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤遂鹊,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后蔗包,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體秉扑,經(jīng)...
    沈念sama閱讀 45,847評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,995評(píng)論 3 338
  • 正文 我和宋清朗相戀三年调限,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了舟陆。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,137評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡耻矮,死狀恐怖秦躯,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情裆装,我是刑警寧澤踱承,帶...
    沈念sama閱讀 35,819評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站哨免,受9級(jí)特大地震影響茎活,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜铁瞒,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,482評(píng)論 3 331
  • 文/蒙蒙 一妙色、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧慧耍,春花似錦身辨、人聲如沸丐谋。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,023評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)号俐。三九已至,卻和暖如春定庵,著一層夾襖步出監(jiān)牢的瞬間吏饿,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,149評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工蔬浙, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留猪落,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,409評(píng)論 3 373
  • 正文 我出身青樓畴博,卻偏偏與公主長(zhǎng)得像笨忌,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子俱病,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,086評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容