使用JavaCV的Groovy for Android会导致NoClassDefFoundError

时间:2014-10-01 08:39:35

标签: android groovy javacv

我在Android项目中使用JavaCV来操作一些图像。 我成功地使用JavaCV的本机库创建了普通Java项目,该应用程序运行正常。 然后我想尝试将项目移植到Groovy for Android:

  

java.lang.NoClassDefFoundError:java / awt / image / BufferedImage               at java.lang.Class.getDeclaredMethods(Native Method)               at java.lang.Class.getDeclaredMethods(Class.java:703)               at org.codehaus.groovy.reflection.stdclasses.CachedSAMClass $ 1.run(CachedSAMClass.java:100)               at org.codehaus.groovy.reflection.stdclasses.CachedSAMClass $ 1.run(CachedSAMClass.java:98)               在java.security.AccessController.doPrivileged(AccessController.java:45)               at org.codehaus.groovy.reflection.stdclasses.CachedSAMClass.getDeclaredMethods(CachedSAMClass.java:98)               at org.codehaus.groovy.reflection.stdclasses.CachedSAMClass.getAbstractMethods(CachedSAMClass.java:116)               at org.codehaus.groovy.reflection.stdclasses.CachedSAMClass.getSAMMethod(CachedSAMClass.java:182)               at org.codehaus.groovy.reflection.ClassInfo.isSAM(ClassInfo.java:344)               at org.codehaus.groovy.reflection.ClassInfo.createCachedClass(ClassInfo.java:334)               at org.codehaus.groovy.reflection.ClassInfo.access $ 700(ClassInfo.java:38)               at org.codehaus.groovy.reflection.ClassInfo $ LazyCachedClassRef.initValue(ClassInfo.java:482)               at org.codehaus.groovy.reflection.ClassInfo $ LazyCachedClassRef.initValue(ClassInfo.java:473)               在org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)               在org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)               at org.codehaus.groovy.reflection.ClassInfo.getCachedClass(ClassInfo.java:108)               at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:107)               在org.codehaus.groovy.reflection.CachedClass $ 4.initValue(CachedClass.java:136)               at org.codehaus.groovy.reflection.CachedClass $ 4.initValue(CachedClass.java:133)               在org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)               在org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)               at org.codehaus.groovy.reflection.CachedClass.getCachedSuperClass(CachedClass.java:243)               在org.codehaus.groovy.reflection.CachedClass $ 8.initValue(CachedClass.java:209)               在org.codehaus.groovy.reflection.CachedClass $ 8.initValue(CachedClass.java:195)               在org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)               在org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)               在org.codehaus.groovy.reflection.CachedClass.getInterfaces(CachedClass.java:247)               在org.codehaus.groovy.reflection.CachedClass。(CachedClass.java:233)               at org.codehaus.groovy.reflection.ClassInfo.createCachedClass(ClassInfo.java:337)               at org.codehaus.groovy.reflection.ClassInfo.access $ 700(ClassInfo.java:38)               at org.codehaus.groovy.reflection.ClassInfo $ LazyCachedClassRef.initValue(ClassInfo.java:482)               at org.codehaus.groovy.reflection.ClassInfo $ LazyCachedClassRef.initValue(ClassInfo.java:473)               在org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)               在org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)               at org.codehaus.groovy.reflection.ClassInfo.getCachedClass(ClassInfo.java:108)               at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:107)               at org.codehaus.groovy.reflection.ParameterTypes.getParametersTypes0(ParameterTypes.java:78)               at org.codehaus.groovy.reflection.ParameterTypes.getParameterTypes(ParameterTypes.java:64)               at org.codehaus.groovy.reflection.CachedMethod.compareToCachedMethod(CachedMethod.java:154)               在org.codehaus.groovy.reflection.CachedMethod.compareTo(CachedMethod.java:137)               at java.util.ComparableTimSort.binarySort(ComparableTimSort.java:228)               在java.util.ComparableTimSort.sort(ComparableTimSort.java:172)               在java.util.ComparableTimSort.sort(ComparableTimSort.java:142)               在java.util.Arrays.sort(Arrays.java:1973)               at org.codehaus.groovy.reflection.CachedClass $ 3.initValue(CachedClass.java:117)               在org.codehaus.groovy.reflection.CachedClass $ 3.initValue(CachedClass.java:79)               在org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)               在org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)               在org.codehaus.groovy.reflection.CachedClass.getMethods(CachedClass.java:255)               在groovy.lang.MetaClassImpl.populateMet

这是使用Javacv的代码段:

            FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outFile, width, height);
            recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);
            recorder.setFormat("mp4");
            recorder.setFrameRate(frameRate);
            recorder.setVideoQuality(videoQuality);
            /* some non Javacv stuff */
                    while(!finished)
                    {
                            opencv_core.IplImage image = cvLoadImage(picPath);
                            recorder.record(image);
                            opencv_core.cvReleaseImage(image);
                    }

我知道Android不附带AWT,但就纯Java项目而言,这不是问题。我只有在使用Groovy时才遇到这个问题。我只花了整个上午试图弄清楚没有运气,也尝试通过Proguard传递生成的调试apk但它只是让人更加困惑。 任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

所以,我自己回答了我的问题。 我花了几天时间才想到这一点:我必须使用本机库为所有方法添加@CompileStatic注释。

值得注意的是,出于性能原因,建议(再次:https://speakerdeck.com/glaforge/groovy-on-android-droidcon-paris-2014)尽可能多地添加@CompileStatic。