首页 > 解决方案 > 如何在不使用任何构建工具的情况下使用 aapt2 编译 Android 应用程序?

问题描述

我正在尝试在 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复制这里可用的东西

标签: androidbashaapt2

解决方案


使用以下链接作为参考,使用 aapt/appt2 编译 java 应用程序,以便您可以自己制作一个用于编译 kotlin。

https://github.com/HemanthJabalpuri/AndroidExplorer


推荐阅读