【发布时间】:2019-01-20 08:12:05
【问题描述】:
我正在尝试在 Android Studio 上编译我刚刚在 Kotlin 中创建的 Android 应用程序,而不使用 Gradle 或任何其他构建工具。我的目的是加快应用程序的编译速度,而无需使用 Android Studio 或安装 Gradle、ant 或 buck 等构建工具。我在使用 aapt2 链接文件时遇到问题。
我正在使用 aapt2 将 res 文件夹中的所有文件编译成一个 zip 文件。但是当我尝试链接它们时,aapt2 会吐出错误。 错误似乎是由于缺少应用程序兼容库,我的问题是如何成功链接所有这些和 kotlin 文件以创建可部署的 apk 文件。
下面编译res文件夹中的所有文件并创建resources.zip文件。
$AAPT compile --dir $APP_DIR/src/main/res -o $APP_DIR/build/intermediate/resources.zip
然而这失败了。
$AAPT link -o $APP_DIR/build/intermediate/ -I $PLATFORM $APP_DIR/build/intermediate/resources.zip --manifest $APP_DIR/src/main/AndroidManifest.xml
出现以下错误
error: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.example.myapplication:style/Theme.AppCompat.Light.DarkActionBar) not found.
./projects/MyApplication/app/src/main/res/values/styles.xml:6: error: style attribute 'attr/colorPrimary (aka com.example.myapplication:attr/colorPrimary)' not found.
./projects/MyApplication/app/src/main/res/values/styles.xml:7: error: style attribute 'attr/colorPrimaryDark (aka com.example.myapplication:attr/colorPrimaryDark)' not found.
./projects/MyApplication/app/src/main/res/values/styles.xml:8: error: style attribute 'attr/colorAccent (aka com.example.myapplication:attr/colorAccent)' not found.
error: resource style/ThemeOverlay.AppCompat.Dark.ActionBar (aka com.example.myapplication:style/ThemeOverlay.AppCompat.Dark.ActionBar) not found.
./projects/MyApplication/app/src/main/res/values/styles.xml:11: error: style attribute 'attr/windowActionBar (aka com.example.myapplication:attr/windowActionBar)' not found.
./projects/MyApplication/app/src/main/res/values/styles.xml:12:
error: style attribute 'attr/windowNoTitle (aka com.example.myapplication:attr/windowNoTitle)' not found.
error: resource style/ThemeOverlay.AppCompat.Light (aka com.example.myapplication:style/ThemeOverlay.AppCompat.Light) not found.
错误:链接引用失败。
这似乎是由于缺少应用程序兼容库。我尝试手动下载 appcompat-v7-27.1.1.aar 文件并链接它,但这失败了。
如果有人遇到此问题的解决方案,请赐教。谢谢。
我想用 aapt2 复制这里可用的内容 https://github.com/authmane512/android-project-template/blob/master/build.sh
【问题讨论】:
-
我怀疑这会“加速编译应用程序”。 Gradle 在避免不必要的编译方面做得很好。您认为哪一部分可以做得更快?
-
加速部分是有问题的,我同意。我只是想看看我是否可以在不使用 Gradle 的情况下完成我正在从事的项目。我的计划是预先下载依赖项 gradle 拉入到一个文件夹中,并在 aapt2 链接阶段添加它们以创建一个中间 apk 文件,然后我可以将其与 kotlin 二进制文件合并。