我在一个由大约 6 个 bundle (android 库项目)组成的项目上遇到构建错误,并且每个包仅在我尝试在 Windows 机器中构建它时才包含大约 10 个模块(在 Mac 中工作正常)。
在某些时候,这种情况开始发生(以前没有发生过),我无法确切知道何时(我很少使用 Windows,而且很多人都提交了这些 bundle/模块)
我收到大约 170 个错误,第一个是:
:bundle-module:processDebugResources
C:\project\trunk\project-bundle\bundle-module\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.2.1\res\values\values.xml:807:5-965:13: AAPT: Error parsing XML: not well-formed (invalid token)
C:\project\trunk\project-bundle\bundle-module\build\intermediates\res\merged\debug\values-hdpi-v4\values-hdpi-v4.xml:4: AAPT: Error retrieving parent for item: No resource found that matches the given name 'Base.Widget.AppCompat.DrawerArrowToggle.Common'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.2.1\res\values-hdpi-v4\values-hdpi-v4.xml:3:5-7:14: AAPT: No resource found that matches the given name: attr 'barLength'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.2.1\res\values-hdpi-v4\values-hdpi-v4.xml:3:5-7:14: AAPT: No resource found that matches the given name: attr 'drawableSize'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\exploded-aar\com.android.support\appcompat-v7\24.2.1\res\values-hdpi-v4\values-hdpi-v4.xml:3:5-7:14: AAPT: No resource found that matches the given name: attr 'gapBetweenBars'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\res\merged\debug\values-sw600dp-v13\values-sw600dp-v13.xml:20: AAPT: Error retrieving parent for item: No resource found that matches the given name 'Base.Widget.Design.TabLayout'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\exploded-aar\com.android.support\design\24.2.1\res\values-sw600dp-v13\values-sw600dp-v13.xml:12:5-15:13: AAPT: No resource found that matches the given name: attr 'tabGravity'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\exploded-aar\com.android.support\design\24.2.1\res\values-sw600dp-v13\values-sw600dp-v13.xml:12:5-15:13: AAPT: No resource found that matches the given name: attr 'tabMode'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\res\merged\debug\values-land\values-land.xml:7: AAPT: Error retrieving parent for item: No resource found that matches the given name 'Base.Widget.Design.TabLayout'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\exploded-aar\com.android.support\design\24.2.1\res\values-land\values-land.xml:3:5-6:13: AAPT: No resource found that matches the given name: attr 'tabGravity'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\exploded-aar\com.android.support\design\24.2.1\res\values-land\values-land.xml:3:5-6:13: AAPT: No resource found that matches the given name: attr 'tabMode'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\res\merged\debug\values-large-v4\values-large-v4.xml:10: AAPT: Error retrieving parent for item: No resource found that matches the given name 'Base.Theme.AppCompat.Dialog.FixedSize'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\res\merged\debug\values-large-v4\values-large-v4.xml:11: AAPT: Error retrieving parent for item: No resource found that matches the given name 'Base.Theme.AppCompat.Light.Dialog.FixedSize'.
C:\project\trunk\project-bundle\bundle-module\build\intermediates\res\merged\debug\values-night-v8\values-night-v8.xml:3: AAPT: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat'
......
......
我尝试过的事情:
最佳答案
好的,我的一位同事看到了这个问题,并找到了解决方案,所以我将其发布在这里。他指出,在我们的 build.gradle 中,我们有以下任务:
String updateStylesResourcesFromConfig(String resourcesTag) {
File jsonFile = file("bundle-module/build/intermediates/exploded-aar/com.company.product/config-bundle/${version}/assets/config/app/styles/android/styles.json")
println "bundle-module/build/intermediates/exploded-aar/com.company.product/config-bundle/${version}/assets/config/app/styles/android/styles.json"
if (jsonFile.exists() && !jsonFile.text.isEmpty()) {
println "Updating style file in ${resourcesTag} mode"
// Reading json file text
def jsonContent = new JsonSlurper().parseText(jsonFile.text)
if (!jsonContent.isEmpty()) {
//Applying JSON file content
def primaryColor = jsonContent.Variables.primaryColor
def secondaryColor = jsonContent.Variables.secondaryColor
def primaryTextColor = jsonContent.Variables.primaryTextColor
println "bundle-module/build/intermediates/res/merged/${resourcesTag.toLowerCase()}/values/values.xml"
File valuesXMLFile = file("bundle-module/build/intermediates/res/merged/${resourcesTag.toLowerCase()}/values/values.xml")
if (valuesXMLFile.exists()) {
def response = new XmlParser().parseText(valuesXMLFile.text)
response.color.each {
def value
switch (it.@name) {
case "primaryColor":
value = primaryColor
break
case "secondaryColor":
value = secondaryColor
break
case "primaryTextColor":
value = primaryTextColor
break
}
if (value != null) {
replaceColorValue(it, value)
}
}
valuesXMLFile.text = XmlUtil.serialize(response)
}
}
}
}
出于某种原因,在 Windows 上,这不能按预期工作。
关于Android 构建仅在 Windows 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46491152/