gpt4 book ai didi

android - 如何在不使用任何构建工具的情况下使用 aapt2 编译 Android 应用程序?

转载 作者:行者123 更新时间:2023-12-05 00:08:36 24 4
gpt4 key购买 nike

我正在尝试在 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

最佳答案

实际上使用额外的支持库是非常困难和困惑的,你会得到这些错误,因为你使用的支持库的主题不是 android.jar 的一部分,而是你可以使用 android.jar 的默认主题。
就放

public  class MainActivity extends Activity {...}

代替
public  class MainActivity extends AppCompatActivity {...}

并将 list 的应用主题更改为指向“styes.xml”,因此基本上您必须将样式 XML 文件更改为这个
<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

</resources>

此外,您应该在“Manifest.xml”文件中使用以下代码将您的项目主题或样式 XML 文件中的 Activity 指向值下
android:theme="@style/AppTheme"

这篇引用文章对您正在尝试做的事情非常有帮助 https://geosoft.no/development/android.html , 还要签署您的 APK 以便在设备上运行您的应用,否则安装时可能会显示错误。
谢谢。

关于android - 如何在不使用任何构建工具的情况下使用 aapt2 编译 Android 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54274657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com