【发布时间】:2017-07-01 09:37:48
【问题描述】:
我在 Unity 中使用这个 C# 代码来访问 Java 类是 .aar lib:
AndroidJavaClass ajc;
private AndroidJavaObject ajo;
// Use this for initialization
void Start () {
ajc = new AndroidJavaClass("com.example.pc.superpoweredsdk.SuperPoweredPlayerWrapper");
ajo = ajc.Get<AndroidJavaObject>("currentActivity");
}
但我在 android 上的 logcat 中收到此错误:
AndroidJavaException: java.lang.NoSuchFieldError: no "Ljava/lang/Object;" “Lcom/example/pc/superpoweredsdk/SuperPoweredPlayerWrapper;”类中的“currentActivity”字段或其超类 07-01 12:31:08.640 1467 1485 I Unity:java.lang.NoSuchFieldError:没有“Ljava/lang/Object;” “Lcom/example/pc/superpoweredsdk/SuperPoweredPlayerWrapper;”类中的“currentActivity”字段或其超类
这是我试图调用的 Java 类和函数:
public class SuperPoweredPlayerWrapper {
public SuperPoweredPlayerWrapper(Context context) {
int sampleRate = 44100;
int bufferSize = 512;
AssetFileDescriptor fd = context.getResources().openRawResourceFd(R.raw.lycka);
int fileOffset = (int)fd.getStartOffset();
int fileLength = (int)fd.getLength();
try {
fd.getParcelFileDescriptor().close();
} catch (IOException e) {
android.util.Log.d("", "Close error.");
}
SuperpoweredPlayer(sampleRate, bufferSize, context.getPackageResourcePath(), fileOffset, fileLength);
}
private native void SuperpoweredPlayer(int sampleRate, int bufferSize, String apkPath, int fileOffset, int fileLength);
public native void playPause(boolean play);
public native void setTempo(double value);
static {
System.loadLibrary("SuperpoweredExample");
}
}
如何使用 Unity 中的上下文参数调用此类构造函数?
【问题讨论】: