使用 Kanzi 进行 Android 应用程序开发故障排除。

  • 如果在构建 Android 软件包或在 Android Studio 中打开工程时收到类似以下的错误:

    Your build is currently configured to use incompatible Java 21.0.3 and Gradle 7.6.2. Cannot sync the project.
    
    Unsupported Java.
    Your build is currently configured to use Java 17.0.6 and Gradle 6.7.1.
    
    Unsupported class file major version 61.
    

    出现这些错误是因为 Gradle 工具与当前使用的 JDK 不匹配。要解决这些错误:

    • 如果您使用 Kanzi 3.9.7 或更早版本创建了应用程序,请迁移您的工程以使用较新的工具。请参阅 对 Android 应用程序模板的更改。

    • 确保您的应用程序设置为使用兼容的 JDK。请参阅 安装 JDK。

  • 如果在构建 Android 软件包时收到以下错误:

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':app.packageDebug'.
    > Failed to obtain compression information for entry
    

    确保将您使用的 Android Studio 版本为 4.1.3 或更新版本。此错误发生在 Android Studio 版本 3.1 上。

  • 如果在构建 Android 软件包时收到以下错误:

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':app.packageDebug'.
    > Java heap space
    

    增加 Gradle 构建系统中的可用堆内存量。例如,在 Android Studio 中打开 <ProjectName>/Application/configs/platforms/android_gradle 项目,在该项目中打开 gradle.properties 文件并设置:

    org.gradle.jvmargs=-Xmx4608m
    
  • 如果在构建 Android 软件包时收到以下错误:

    FAILURE: Build failed with an exception.
    
    * Where:
    Build file 'Engine\configs\platforms\android_gradle\kanziruntime\build.gradle' line: 103
    
    * What went wrong:
    A problem occurred evaluating project ':kanziruntime'.
    > <PathToKanziWorkspace>\Engine\version.txt not found
    

    在项目的 <ProjectName>/Application/configs/platforms/android_gradle 目录中创建一个名为 local.properties 的文件,并在该文件中设置工作区的正确位置。例如,设置:

    kanzi.home=C\:\\<KanziWorkspace>
    
  • 当您在构建使用 Data_source_plugin_template 的应用程序时收到此警告:

    More than one file was found with OS independent path 'lib/arm64-v8a/libkzcoreui.so'.
    This version of the Android Gradle Plugin chooses the file from the app or dynamic-feature
    module, but this can cause unexpected behavior or errors at runtime. Future versions of
    the Android Gradle Plugin will throw an error in this case
    

    将 Kanzi Gradle 插件更新到版本 0.7.1。

  • 当在运行 Android 应用程序时收到以下异常之一:

    java.lang.BootstrapMethodError: Exception from call site #0 bootstrap method
    
    E/AndroidRuntime: FATAL EXCEPTION: main
    Process: <process name>, PID: <pid>
    java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
      at com.rightware.kanzi.KanziViewAdapter.loadStartupPrefab(KanziViewAdapter.java:664)
      at com.rightware.kanzi.KanziViewAdapter.setStartupPrefabUrl(KanziViewAdapter.java:196)
    

    您的应用程序很可能使用了不兼容的 Java 版本。Kanzi Android framework (droidfw) 和 Kanzi Java API 需要 Java 8 (1.8)。

    在您的 Android Studio 项目的 app/build.gradle 文件中,确保将 Java 语言版本设置为兼容版本:

    android {
        ...
    
        compileOptions {
           sourceCompatibility JavaVersion.VERSION_1_8
           targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    
  • 当使用 Android Studio 将 Java 项目转换为 Kotlin 时,默认生成的 gradle 脚本默认情况下使用最新版本的 Kotlin。这可能会导致类似于以下的错误:

    The minCompileSdk (31) specified in a
    dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
    is greater than this module's compileSdkVersion (android-28).
    Dependency: androidx.core:core-ktx:1.8.0-alpha01.
    

    确保将 Kotlin 的版本与您的项目兼容。例如,如果您的项目使用 compileSdkVersion 28,请将 Kotlin 降级到版本 1.6.0。

    替换 (Replace)

    implementation "androidx.core:core-ktx:+"
    

    通过

    implementation "androidx.core:core-ktx:1.6.0"
    

    或

    implementation "androidx.core:core-ktx:$kotlin_version"
    
  • 当您从 Android 应用程序收到这些错误消息时:

    I/Kanzi: [info:generic] kzsEGLConfigure(): no EGL configurations with GLES3 support present, downgraded EGL configuration request to GLES2.
    
    E/Kanzi: [error:generic] Half-float is not supported by current platform, please re-export kzb file(s) without half-floats.
    

    该应用程序使用仅在 OpenGL ES 3.0 中可用的功能。在 Android 模拟器中,启用 OpenGL ES 3.0。请参阅 在 Android 模拟器中启用 OpenGL ES 3.0。