我正在尝试使用JTransforms库在Android应用(使用最新的Android Studio)中计算数学函数(DoubleFFT_1D)。我正在使用JTransforms website提供的.jar文件,并将其导入到项目中。我已经尝试了JTransforms修订版2.4和3.1。该代码编译没有错误,但是当我到达实际的方法调用时,我收到以下错误消息:

09-07 17:30:11.369 E/JavaBinder: *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
                                 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jtransforms/fft/DoubleFFT_1D;
                                     at com.algoint.libzante.AutoCorrelation.compute(AutoCorrelation.java:66)
                                     at com.algoint.libzante.EstimateACF.estimateInSamplePeriods(EstimateACF.java:104)
                                     at <snip>
com.algoint.zante.BluetoothLeService.broadcastUpdate(BluetoothLeService.java:348)
                                     at com.algoint.zante.BluetoothLeService.access$700(BluetoothLeService.java:50)
                                     at com.algoint.zante.BluetoothLeService$1.onCharacteristicChanged(BluetoothLeService.java:243)
                                     at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:438)
                                     at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:399)
                                     at android.os.Binder.execTransact(Binder.java:453)
                                  Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jtransforms.fft.DoubleFFT_1D" on path: DexPathList[[dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-json_simple-1.1_9ec115b071c72fb6edf2028f7a57e4ae60bb5a65-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-dropbox-android-sdk-1.5.4_74a0c4010a6328c8c6443241412fa9c5c398a9ab-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-achartengine-1.1.0_0238cc7eb0f70b6065b267fb6df8a8f6b48a5319-classes.dex"],nativeLibraryDirectories=[/data/app/com.algoint.zante-2/lib/arm64, /vendor/lib64, /system/lib64]]
                                     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                     at com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(IncrementalClassLoader.java:90)
                                     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                     at com.algoint.libzante.AutoCorrelation.compute(AutoCorrelation.java:66) 
                                     at com.algoint.libzante.EstimateACF.estimateInSamplePeriods(EstimateACF.java:104) 
                                     at <snip>
com.algoint.zante.BluetoothLeService.broadcastUpdate(BluetoothLeService.java:348) 
                                     at com.algoint.zante.BluetoothLeService.access$700(BluetoothLeService.java:50) 
                                     at com.algoint.zante.BluetoothLeService$1.onCharacteristicChanged(BluetoothLeService.java:243) 
                                     at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:438) 
                                     at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:399) 
                                     at android.os.Binder.execTransact(Binder.java:453) 
                                    Suppressed: java.lang.ClassNotFoundException: Didn't find class "org.jtransforms.fft.DoubleFFT_1D" on path: DexPathList[[zip file "/data/app/com.algoint.zante-2/base.apk"],nativeLibraryDirectories=[/data/app/com.algoint.zante-2/lib/arm64, /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:504)
                                            ... 12 more
                                        Suppressed: java.lang.ClassNotFoundException: Didn't find class "org.jtransforms.fft.DoubleFFT_1D" on path: DexPathList[[dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.algoint.zante/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.

我在源文件中导入了jtransforms,如下所示:
import org.jtransforms.fft.DoubleFFT_1D;

带有正确的gradle条目:
apply plugin: 'java'
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/JTransforms-3.1-with-dependencies.jar')
}

以及相应的Android Studio依赖项设置:

该项目编译没有错误,并在以下行中引发了错误:
int n = 2 * nextPow2(x.length);
// Twice the number of elements are required: real and imaginary parts of the FFT are stored consecutively
double[] f = new double[2 * n];
System.arraycopy(x, 0, f, 0, x.length);
// FFT
DoubleFFT_1D fft = new DoubleFFT_1D((long) n);  // ERROR ON THIS LINE
// Use "full" to avoid more machinations with symmetry
fft.realForwardFull(f);

引发错误时,n的值为1024,而x的长度为500。
我同时发现了此错误:“JTransforms-2.4.jar”和“JTransforms-3.1-with-dependencies.jar”。我认为原始项目是在Maven中编译的,这有区别吗?
您能推荐任何解决方案吗?
谢谢。

最佳答案

最终,我找到了解决方案。我忽略了.jar文件,只是将源代码直接编译到项目中。程序:
-提取了Jtransforms的完整git存储库,
-将其从Maven项目转换为Gradle项目(“gradle init”),
-将其作为模块导入到我的项目中,然后
-编译进去。
我确实在删除所有原始.jar文件(埋在目录中)时遇到了一些麻烦,但是一旦完成,项目就可以编译并运行良好。

07-24 09:27