gpt4 book ai didi

android - 按产品口味配置 applicationId 后找不到 R 类

转载 作者:搜寻专家 更新时间:2023-11-01 09:28:40 26 4
gpt4 key购买 nike

我的应用程序中有两种风格,我希望每种风格都有不同的 applicationId。这是我的:

defaultConfig {
applicationId "com.mycompany.app"
//more stuff
}

...

productFlavors {
firstflavor {
applicationIdSuffix '.first'
//more stuff
}
secondflavor {
applicationIdSuffix '.second'
//more stuff
}
}

AndroidManifest.xml 中,我有 package="com.mycompany.app",所有代码都在那个包下。

当我用 flavor firstflavor 组装它时,我得到这个错误:

Error:The generated com.mycompany.app.first.R class cannot be found

不应该在com.company.app下生成R.class而不是com.company.app.first吗?

package和application id有什么关系?

如果我删除应用程序 ID flavor 配置 (applicationIdSuffix),一切正常。

编辑

我读过这个here :

If the BuildConfig.java and R.java files was set to the applicationId rather than the package name, then the code which referenced these would need to have different imports for different build variants – in other words you would need to have separate source sets (with huge amounts of duplication) for your different build flavors in order to access these. This would have some quite profound implications for the maintainability of our code.

但是,错误提示找不到 com.mycompany.app.first.R。但是,com.mycompany.app.first 是应用程序 ID,而不是程序包名称!这是为什么?

我正在使用 Android 注释 3.3.2

最佳答案

我找到了解决方案 here .正如我所说,我正在使用 Android Annotations,所以我需要在 apt 插件中配置包名称:

apt {
arguments {
//more things
resourcePackageName "com.mycompany.app" //add this line
}
}

一切正常。

关于android - 按产品口味配置 applicationId 后找不到 R 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49032885/

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