致命异常 NoClassDefFoundError

FATAL EXCEPTION NoClassDefFoundError

in Android 我想执行一个脚本。所以我从

添加了 JavaScript 引擎

http://www.java2s.com/Code/JarDownload/jsr223/jsr223.jar.zip

我的gradle(模块:app)说:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.google.apis:google-api-services-youtube:v3-rev162-1.21.0'
    compile 'joda-time:joda-time:2.3'
    compile files('libs/jsr223.jar')
}

如果我是 运行 应用程序并单击初始化脚本引擎的按钮,我收到以下错误。

有什么解决办法吗?

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2     
Process: com.myApplication, PID: 25387      
java.lang.RuntimeException: An error occured while executing doInBackground()       
    at android.os.AsyncTask.done(AsyncTask.java:304)      
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)        
    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)        
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)     
    at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)        
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)      
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)      
    at java.lang.Thread.run(Thread.java:818)        
 Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lsun/misc/Service;        
    at javax.script.ScriptEngineManager.initEngines(ScriptEngineManager.java:90)        
    at javax.script.ScriptEngineManager.access[=11=](ScriptEngineManager.java:86)       
    at javax.script.ScriptEngineManager.run(ScriptEngineManager.java:80)      
    at java.security.AccessController.doPrivileged(AccessController.java:45)        
    at javax.script.ScriptEngineManager.init(ScriptEngineManager.java:78)       
    at javax.script.ScriptEngineManager.<init>(ScriptEngineManager.java:51)     
    at com.linkgrabber.LinkgrabberSecured.getDecodedSignature(LinkgrabberSecured.java:202)      
    at com.linkgrabber.LinkgrabberSecured.getHttpLinks(LinkgrabberSecured.java:65)      
    at com.myApplication.MainActivity$AsyncLinkGrabber.doInBackground(MainActivity.java:651)        
    at com.myApplication.MainActivity$AsyncLinkGrabber.doInBackground(MainActivity.java:637)        
    at android.os.AsyncTask.call(AsyncTask.java:292)      
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)     
    at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)        
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)      
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)      
    at java.lang.Thread.run(Thread.java:818)        
 Caused by: java.lang.ClassNotFoundException: Didn't find class "sun.misc.Service" on path: DexPathList[[zip file "/data/app/com.myApplication-2/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]        
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)       
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)        
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)        
    at javax.script.ScriptEngineManager.initEngines(ScriptEngineManager.java:90)        
    at javax.script.ScriptEngineManager.access[=11=](ScriptEngineManager.java:86)       
    at javax.script.ScriptEngineManager.run(ScriptEngineManager.java:80)      
    at java.security.AccessController.doPrivileged(AccessController.java:45)        
    at javax.script.ScriptEngineManager.init(ScriptEngineManager.java:78)       
    at javax.script.ScriptEngineManager.<init>(ScriptEngineManager.java:51)         
    at com.linkgrabber.LinkgrabberSecured.getDecodedSignature(LinkgrabberSecured.java:202)      
    at com.linkgrabber.LinkgrabberSecured.getHttpLinks(LinkgrabberSecured.java:65)      
    at com.myApplication.MainActivity$AsyncLinkGrabber.doInBackground(MainActivity.java:651)        
    at com.myApplication.MainActivity$AsyncLinkGrabber.doInBackground(MainActivity.java:637)        
    at android.os.AsyncTask.call(AsyncTask.java:292)      
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)         
    at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)        
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)      
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)      
    at java.lang.Thread.run(Thread.java:818)        
    Suppressed: java.lang.ClassNotFoundException: sun.misc.Service  
    at java.lang.Class.classForName(Native Method)      
    at java.lang.BootClassLoader.findClass(ClassLoader.java:781)        
    at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)        
    at java.lang.ClassLoader.loadClass(ClassLoader.java:504)        
            ... 17 more
 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available     

您正在导入 sun.misc.service。我想你的意思可能是 android.app.Service。因此您无法加载它(android 不包括 sun.misc.Service)。或者您需要将其与您的应用程序打包在一起。