Android 构建仅在 Windows 上失败

标签 android windows gradle

我在一个由大约 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'
......
......

我尝试过的事情:
  • 清洁项目。
  • 使缓存无效并重新启动。
  • 重新 checkout 整个项目。
  • 将项目移到靠近驱动器的根目录(对于文件名长度问题)。
  • 在不同的 Windows 机器上尝试。
  • 删除 Android Studio、属性和 SDK 并从头开始安装。
  • 切换支持库版本。
  • 最佳答案

    好的,我的一位同事看到了这个问题,并找到了解决方案,所以我将其发布在这里。他指出,在我们的 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/

    相关文章:

    c# - 为什么我的 Windows 服务会在大约 5 秒后自动退出?

    android - ClassNotFoundException 当 "implementation"用于库的库依赖时

    android - ServiceStack.Redis 从统一导出的 .apk 文件中抛出 PlatformNotSupported 异常

    android - 如何使用从主表加载数据的 CursorLoader 从子表中检索数据?

    windows - 无法在 Windows 上从/usr/local/ssl/openssl.cnf 加载配置信息

    使用 VS2010 开发 Windows Mobile 应用程序

    maven - gradle依赖关系返回一个rar文件,而不是jar文件

    gradle - 添加 Gradle 插件任务以构建调用

    java - 为什么一个后台线程与主服务线程具有相同的线程ID?

    android - 错误膨胀类