【问题标题】:Android release build fail after upgrading to Gradle wrapper to 7.0.2 and JDK 11升级到 Gradle 包装器到 7.0.2 和 JDK 11 后,Android 版本构建失败
【发布时间】:2021-08-09 20:54:14
【问题描述】:

我已将我的 Android Studio 更新为 Artic Fox,并将 Gradle 包装器更新为 7.0.2(插件 7.0.0)和 JDK 1.8 -> 11。

当我通过 Android Studio 在我的设备上安装调试版本时,它可以正常工作,并且没有错误。

现在,每当我尝试创建发布版 APK 时,构建总是会失败并出现 Lint 错误。不知道发生了什么。

w: Runtime JAR files in the classpath have the version 1.4, which is older than the API version 1.5. Consider using the runtime of version 1.5, or pass '-api-version 1.4' explicitly to restrict the available APIs to the runtime of version 1.4. You can also pass '-language-version 1.4' instead, which will restrict not only the APIs to the specified version, but also the language features
w: /Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.4.10/998caa30623f73223194a8b657abd2baec4880ea/kotlin-stdlib-jdk8-1.4.10.jar: Runtime JAR file has version 1.4 which is older than required for API version 1.5
w: /Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.4.31/84ce8e85f6e84270b2b501d44e9f0ba6ff64fa71/kotlin-stdlib-jdk7-1.4.31.jar: Runtime JAR file has version 1.4 which is older than required for API version 1.5
w: /Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.32/461367948840adbb0839c51d91ed74ef4a9ccb52/kotlin-stdlib-1.4.32.jar: Runtime JAR file has version 1.4 which is older than required for API version 1.5
w: /Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.32/ef50bfa2c0491a11dcc35d9822edbfd6170e1ea2/kotlin-stdlib-common-1.4.32.jar: Runtime JAR file has version 1.4 which is older than required for API version 1.5
/src/main/AndroidManifest.xml:23: Error: SplashScreenActivity must extend android.app.Activity [Instantiatable]
            android:name="com.abc.xyz.activity.SplashScreenActivity"
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/src/main/AndroidManifest.xml:36: Error: MainActivity must extend android.app.Activity [Instantiatable]
            android:name="com.abc.xyz.activity.MainActivity"
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/src/main/AndroidManifest.xml:66: Error: PlayerActivity must extend android.app.Activity [Instantiatable]
            android:name="com.abc.xyz.activity.PlayerActivity"
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   Explanation for issues of type "Instantiatable":
/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.4.10/998caa30623f73223194a8b657abd2baec4880ea/kotlin-stdlib-jdk8-1.4.10.jar: Runtime JAR file has version 1.4 which is older than required for API version 1.5

   Activities, services, broadcast receivers etc. registered in the manifest
   file (or for custom views, in a layout file) must be "instantiatable" by
   the system, which means that the class must be public, it must have an
   empty public constructor, and if it's an inner class, it must be a static
   inner class.

/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.4.31/84ce8e85f6e84270b2b501d44e9f0ba6ff64fa71/kotlin-stdlib-jdk7-1.4.31.jar: Runtime JAR file has version 1.4 which is older than required for API version 1.5

3 errors, 0 warnings
Lint found fatal errors while assembling a release target.

To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}

我不知道为什么我的活动中有Instantiatable 错误。所有这些活动都扩展了一个BaesActivity,它扩展了AppCompatActivity。所以这个错误并没有任何意义。 但是当我将 Gradle 包装器降级到 6.7.1(插件 4.2.2)和 JDK 1.8 时……一切运行顺利。

另外,我也有类似的警告

/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.4.10/998caa30623f73223194a8b657abd2baec4880ea/kotlin-stdlib-jdk8-1.4.10.jar: Runtime JAR file has version 1.4 which is older than required for API version 1.5

这是什么警告,我该如何解决?

【问题讨论】:

  • 我对 AGP 7.0.2 有同样的错误。你已经解决了吗?
  • @GabiMoreno 我没有找到合适的方法,所以我现在恢复到 AGP 4.2.2 和 JDK 1.8
  • 好的。谢谢,@Nishant ????

标签: java android android-studio kotlin gradle


【解决方案1】:

经过大量搜索,我找到了解决方案。

由于Instantiatable lint 检查,构建失败。

Activities, services, broadcast receivers etc. registered in the manifest
   file (or for custom views, in a layout file) must be "instantiatable"

有几个解决方案,

  1. 更新应用程序级别 build.gradle(但不可取)
android {
    lintOptions {
        disable "Instantiatable"
    }
}
  1. 如果您的应用程序依赖于库模块(像我一样,我在库模块中有 BaseActivities),则在库模块上禁用 minifyEnabled,除非您尝试发布库模块( .aar 文件)。

参考here的问题。

更具体地说,来自here的这条评论。

【讨论】:

    【解决方案2】:

    转到文件 -> 设置,搜索 Kotlin Complier 并将语言版本更改为 1.4

    在编译器设置中,可以设置api版本、语言版本和命令行参数。

    【讨论】:

    • @A Farmanbar,我试过了,但没有用。
    • @Nishant 很有趣,你清理并重新构建项目了吗?
    【解决方案3】:

    我遇到了同样的问题。我可以用这个技巧解决: 1) 清洁项目 2) 重建项目 3)用一些API打开模拟器 4) 从 Debug 更改为 Release(Active Build Variant) 5) 构建包/APKs > 构建包

    我不知道它是否适合你。

    【讨论】:

      猜你喜欢
      • 2018-01-19
      • 2023-03-08
      • 2018-10-10
      • 1970-01-01
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-07
      相关资源
      最近更新 更多