Неустранимое исключение NoClassDefFoundError

В Android хочу выполнить скрипт. Поэтому я добавил движок JavaScript из

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

Мой Gradle (Модуль: приложение) говорит:

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$3.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$1.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$0(ScriptEngineManager.java:86)       
    at javax.script.ScriptEngineManager$1.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$2.call(AsyncTask.java:292)      
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)     
    at android.os.AsyncTask$SerialExecutor$1.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$0(ScriptEngineManager.java:86)       
    at javax.script.ScriptEngineManager$1.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$2.call(AsyncTask.java:292)      
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)         
    at android.os.AsyncTask$SerialExecutor$1.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     

1 ответ

Решение

Вы импортируете sun.misc.service. Я думаю, что вы, вероятно, имели в виду android.app.Service. В результате вы не можете загрузить его (Android не включает Sun.misc.Service). Либо так, либо вам нужно упаковать его в свое приложение.

Другие вопросы по тегам