Android风格和资源文件
我对android gradle构建有问题。长话短说,我创造了两种口味:Android风格和资源文件,android,gradle,android-productflavors,Android,Gradle,Android Productflavors,我对android gradle构建有问题。长话短说,我创造了两种口味: productFlavors{ abcDemoFree{ } abcDemo{ } } xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://sche
productFlavors{
abcDemoFree{
}
abcDemo{
}
}
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
Eeach flavor对此活动有自己的活动(Settings.java)和布局(Settings\u layout.xml)。
从main中删除了这两个文件,因此Settings.java和Settings_layout.xml仅存在于flavors中
abcDemoFree
- java
- Settings.java
- res
- settings_layout.xml
abcDemo
- java
- Settings.java
- res
- settings_layout.xml
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
Android Studio创建了4个构建变体:
abcDemoFreeDebug
abcDemoFreeRelease
abcDemoDebug
abcDemoRelease
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
一切都很好,我能够创造出apk的行为,我期待从每一种味道。
问题是,当我切换到一个buildVariant时,比如abcDemoDebug,android studio会以另一种风格在我的
来自abcDemoFreeDegub/res/settings_layout.xml的示例
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
</LinearLayout>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
生成错误:未注册URI
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
如何消除这些错误?或者这是正常的行为 不幸的是,AndroidStudio在切换时使用了错误风格的资源。您必须在切换变体后进行清理,然后进行生成,以消除这些错误。如果您实际上没有切换生成变体,则会出现错误。如果您只是查看该文件,它将显示错误,但是如果您实际切换构建配置并重新构建,您将很好。还要确认您没有针对以下口味执行特定的实现或编译:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
MyFavorImplementation.android.libraries.Example
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
那样的话,它将丢失清除警告所需的库
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
使用构建变体滑出更改为其他调试构建,它应该自动重建,但如果不是,只需自己重建即可。另外,请确保您查看的是实际文件,而不是生成的文件,因为有时您使用的是注释工具或布局包装器的数据绑定,并且布局和第一个子标记中有android标记。这可能会导致在生成最终布局文件时,这些文件也是红色的
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"