uni-app java.lang.NoClassDefFoundError: Failed resolution of: Ljava/nio/file/Paths;
uni-app java.lang.NoClassDefFoundError: Failed resolution of: Ljava/nio/file/Paths;
产品分类:uni小程序SDK
手机系统:Android
手机系统版本号:Android 7.1.1
手机厂商:RK3399
手机机型:RK3399
页面类型:vue
SDK版本号:V2
操作步骤:
android 7 执行 DCUniMPSDK.getInstance().releaseWgtToRunPath 直接报错
预期结果:
android 7 执行 DCUniMPSDK.getInstance().releaseWgtToRunPath 正常使用
实际结果:
android 7 执行 DCUniMPSDK.getInstance().releaseWgtToRunPath 直接报错
bug描述:
https://nativesupport.dcloud.net.cn/UniMPDocs/UseSdk/android.html
说 Android API 最低运行版本 21
但是提供的方法 DCUniMPSDK.getInstance().releaseWgtToRunPath() 中依赖了 Paths的api
Paths相关的api 是 andoird O(26+) 才支持的
请问这个bug你们会fix吗
更多关于uni-app java.lang.NoClassDefFoundError: Failed resolution of: Ljava/nio/file/Paths;的实战教程也可以访问 https://www.itying.com/category-93-b0.html
官方有人吗
更多关于uni-app java.lang.NoClassDefFoundError: Failed resolution of: Ljava/nio/file/Paths;的实战教程也可以访问 https://www.itying.com/category-93-b0.html
你好,你这个问题解决了吗?我现在线上异常也有报这个bug,而且都是Android7系统以下的手机,我们项目要求使用的Java11,配置的是Java11的语法支持,这个:compileOptions { targetCompatibility JavaVersion.VERSION_11 sourceCompatibility JavaVersion.VERSION_11 } kotlinOptions{ jvmTarget=JavaVersion.VERSION_11 } 按时11应该是向下兼容Java8的,后台看依然有报错。
Paths相关的api 是 andoird O(26+) .
这个不是android的api,是java的api
因为android 自带的是java7 ,
你参考一下demo .配置上 java 8的语法支持就可以了。
对, 我可以自己实现 wgt的解压缩, 我只是想问文档上既然支持到 andorid 21, 那sdk里写的时候, 要么判断一下android版本号, 要么就干脆用 1.7的api去写, 难道这个不算bug么, 如果不fix, 那请你们更新文档, 说支持android O+呀
android7升级wgt,下载完成后解压会报这个错误
我现在线上异常也有报这个bug,而且都是Android7系统以下的手机,我们项目要求使用的Java11,配置的是Java11的语法支持,这个:compileOptions {
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_11
}
kotlinOptions{
jvmTarget=JavaVersion.VERSION_11
}
Java11应该是向下兼容Java8的,后台看依然有报错。
为了兼容Android7以下手机,在Android7以下系统的手机无法覆盖安装,需要先判断本地是否已安装过,如果之前有安装过,需要先删除安装的文件后再调用releaseWgtToRunPath方法解压安装。
MI 9:10
vivo:13,12
HUAWEI:10
我们这边大致统计了一下这类报错的,高版本android系统也会报错
我们这边统计到崩溃主要集中在android8以下。所以,就先知处理了Andorid8以下的。解压前先把老的删除了。高系统的先没处理,后续再看
The error java.lang.NoClassDefFoundError: Failed resolution of: Ljava/nio/file/Paths;
typically occurs in a Java or Android environment when the specified class (java.nio.file.Paths
) cannot be found or loaded at runtime. This issue can arise for several reasons, especially in the context of uni-app or Android development.
Possible Causes and Solutions:
-
Java Version Compatibility:
- The
java.nio.file.Paths
class is part of the Java NIO (New I/O) package, which was introduced in Java 7. If you’re using an older version of Java (e.g., Java 6 or earlier), this class will not be available. - Solution: Ensure that your project is using Java 7 or later. In Android Studio, you can configure the Java version in your
build.gradle
file:android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
- The
-
Android API Level:
- The
java.nio.file
package is not fully supported on older Android devices. ThePaths
class is part of thejava.nio.file
package, which was introduced in Android API level 26 (Android 8.0). - Solution: If you’re targeting older Android versions (below API 26), you cannot use
java.nio.file.Paths
. Instead, use alternative methods for file handling, such asjava.io.File
.
- The
-
ProGuard/R8 Configuration:
- If you’re using ProGuard or R8 for code shrinking and obfuscation, it might be removing or obfuscating the
java.nio.file.Paths
class. - Solution: Add a rule to your
proguard-rules.pro
file to keep thejava.nio.file.Paths
class:-keep class java.nio.file.Paths { *; }
- If you’re using ProGuard or R8 for code shrinking and obfuscation, it might be removing or obfuscating the
-
Missing Dependencies:
- Ensure that all necessary dependencies are included in your project. If you’re using a library that relies on
java.nio.file.Paths
, make sure it’s properly added to yourbuild.gradle
file. - Solution: Verify and add any missing dependencies.
- Ensure that all necessary dependencies are included in your project. If you’re using a library that relies on
-
Uni-App Specific Issues:
- Uni-app is a cross-platform framework, and if you’re encountering this issue in a uni-app project, it might be related to the native Android code or plugins you’re using.
- Solution: Check if any native Android plugins or modules in your uni-app project are using
java.nio.file.Paths
. If so, ensure they are compatible with your target Android API level.
Example of Alternative Implementation:
If you cannot use java.nio.file.Paths
due to compatibility issues, you can use java.io.File
for basic file operations. For example:
import java.io.File;
public class FileExample {
public static void main(String[] args) {
File file = new File("path/to/your/file.txt");
if (file.exists()) {
System.out.println("File exists!");
} else {
System.out.println("File does not exist.");
}
}
}