Python に既存のコードがいくつかあり、Kivy と Buildozer を使用して Android に移植したいと考えています。ただし、ネイティブ Android クラス 'Visualizer' に依存しています。アプリケーションは正しく起動しますが、アプリケーションの [実行] ボタンをクリックすると、Java で次のコードを使用するとこのエラーが表示されます
new Visualizer(0);
また
Visualizer = autoclass('[visualizer.class.....]')
v = Visualizer(0)
パイソンで
RECORD_AUDIO、MODIFY_AUDIO、INTERNET など、必要なすべてのランタイム権限を付与しました
ERROR:
06-18 11:25:46.852 24619 24619 D VisualDj: Called set_on_data_capture_listener
06-18 11:25:46.892 24619 24619 D VisualDj: setPlayer1
06-18 11:25:46.968 24622 24622 I crash_dump32: performing dump of process 24619 (target tid = 24619)
06-18 11:25:46.969 24622 24622 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-18 11:25:46.969 24622 24622 F DEBUG : Build fingerprint: 'HONOR/PRA-TL10/HWPRA-H:8.0.0/HONORPRA-TL10/373(C10):user/release-keys'
06-18 11:25:46.969 24622 24622 F DEBUG : Revision: '0'
06-18 11:25:46.969 24622 24622 F DEBUG : ABI: 'arm'
06-18 11:25:46.969 24622 24622 F DEBUG : pid: 24619, tid: 24619, name: SDLThread >>> org.vd.visualdj <<<
06-18 11:25:46.969 24622 24622 F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xd03a6020
06-18 11:25:46.969 24622 24622 F DEBUG : r0 00000000 r1 00000001 r2 00000000 r3 00000000
06-18 11:25:46.969 24622 24622 F DEBUG : r4 ef6e4540 r5 d03a6020 r6 00000018 r7 d03a6008
06-18 11:25:46.969 24622 24622 F DEBUG : r8 cd7f3dbc r9 cd7f3dbc sl 80047204 fp 00000000
06-18 11:25:46.969 24622 24622 F DEBUG : ip f50f0d94 sp cd7f3c88 lr f50cfc65 pc f50cf23a cpsr 600b0030
06-18 11:25:47.268 24622 24622 F DEBUG :
06-18 11:25:47.268 24622 24622 F DEBUG : backtrace:
06-18 11:25:47.268 24622 24622 F DEBUG : #00 pc 0005223a /system/lib/libbinder.so (_ZN7android6Parcel19ipcSetDataReferenceEPKhjPKyjPFvPS0_S2_jS4_jPvES6_+61)
06-18 11:25:47.268 24622 24622 F DEBUG : #01 pc 00049347 /system/lib/libbinder.so (_ZN7android14IPCThreadState15waitForResponseEPNS_6ParcelEPi+350)
06-18 11:25:47.268 24622 24622 F DEBUG : #02 pc 00048fd1 /system/lib/libbinder.so (_ZN7android14IPCThreadState8transactEijRKNS_6ParcelEPS1_j+152)
06-18 11:25:47.268 24622 24622 F DEBUG : #03 pc 000419d1 /system/lib/libbinder.so (_ZN7android8BpBinder8transactEjRKNS_6ParcelEPS1_j+36)
06-18 11:25:47.268 24622 24622 F DEBUG : #04 pc 0004bba3 /system/lib/libbinder.so (_ZNK7android16BpServiceManager12checkServiceERKNS_8String16E+74)
06-18 11:25:47.268 24622 24622 F DEBUG : #05 pc 0004bacb /system/lib/libbinder.so (_ZNK7android16BpServiceManager10getServiceERKNS_8String16E+190)
06-18 11:25:47.268 24622 24622 F DEBUG : #06 pc 0002ba6d /system/lib/libaudioclient.so (_ZN7android11AudioSystem17get_audio_flingerEv+144)
06-18 11:25:47.268 24622 24622 F DEBUG : #07 pc 000276cd /system/lib/libaudioclient.so (_ZN7android11AudioEffect3setEPK12audio_uuid_sS3_iPFviPvS4_ES4_15audio_session_ti+60)
06-18 11:25:47.268 24622 24622 F DEBUG : #08 pc 0002767d /system/lib/libaudioclient.so (_ZN7android11AudioEffectC1EPK12audio_uuid_sRKNS_8String16ES3_iPFviPvS7_ES7_15audio_session_ti+88)
06-18 11:25:47.268 24622 24622 F DEBUG : #09 pc 000814e5 /system/lib/libmedia.so (_ZN7android10VisualizerC1ERKNS_8String16EiPFviPvS4_ES4_15audio_session_t+44)
06-18 11:25:47.268 24622 24622 F DEBUG : #10 pc 000033bd /system/lib/libaudioeffect_jni.so (_ZL37android_media_visualizer_native_setupP7_JNIEnvP8_jobjectS2_iP10_jintArrayP8_jstring+196)
06-18 11:25:47.268 24622 24622 F DEBUG : #11 pc 00cbfc27 /system/framework/arm/boot-framework.oat (offset 0x5f6000) (android.media.audiofx.Visualizer.native_setup+150)
06-18 11:25:47.268 24622 24622 F DEBUG : #12 pc 003e0931 /system/lib/libart.so (art_quick_invoke_stub_internal+64)
06-18 11:25:47.268 24622 24622 F DEBUG : #13 pc 003e4ea3 /system/lib/libart.so (art_quick_invoke_stub+226)
06-18 11:25:47.268 24622 24622 F DEBUG : #14 pc 000ac2d9 /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+140)
06-18 11:25:47.268 24622 24622 F DEBUG : #15 pc 001f27fb /system/lib/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+238)
06-18 11:25:47.268 24622 24622 F DEBUG : #16 pc 001edd71 /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+576)
06-18 11:25:47.268 24622 24622 F DEBUG : #17 pc 003cb72d /system/lib/libart.so (MterpInvokeDirect+356)
06-18 11:25:47.268 24622 24622 F DEBUG : #18 pc 003d2d14 /system/lib/libart.so (ExecuteMterpImpl+14484)
06-18 11:25:47.268 24622 24622 F DEBUG : #19 pc 001d5351 /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+340)
06-18 11:25:47.268 24622 24622 F DEBUG : #20 pc 001da6a3 /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+142)
06-18 11:25:47.268 24622 24622 F DEBUG : #21 pc 001edd5b /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+554)
06-18 11:25:47.268 24622 24622 F DEBUG : #22 pc 003cb72d /system/lib/libart.so (MterpInvokeDirect+356)
06-18 11:25:47.268 24622 24622 F DEBUG : #23 pc 003d2d14 /system/lib/libart.so (ExecuteMterpImpl+14484)
06-18 11:25:47.268 24622 24622 F DEBUG : #24 pc 001d5351 /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+340)
06-18 11:25:47.268 24622 24622 F DEBUG : #25 pc 001da5f1 /system/lib/libart.so (_ZN3art11interpreter30EnterInterpreterFromEntryPointEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameE+92)
06-18 11:25:47.268 24622 24622 F DEBUG : #26 pc 003c0fbd /system/lib/libart.so (artQuickToInterpreterBridge+944)
06-18 11:25:47.268 24622 24622 F DEBUG : #27 pc 003e46f1 /system/lib/libart.so (art_quick_to_interpreter_bridge+32)
06-18 11:25:47.268 24622 24622 F DEBUG : #28 pc 003e0931 /system/lib/libart.so (art_quick_invoke_stub_internal+64)
06-18 11:25:47.268 24622 24622 F DEBUG : #29 pc 003e4ea3 /system/lib/libart.so (art_quick_invoke_stub+226)
06-18 11:25:47.268 24622 24622 F DEBUG : #30 pc 000ac2d9 /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+140)
06-18 11:25:47.268 24622 24622 F DEBUG : #31 pc 00334bb1 /system/lib/libart.so (_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectAccessAlreadyRunnableEPNS_9ArtMethodEPNS_8ArgArrayEPNS_6JValueEPKc+52)
06-18 11:25:47.268 24622 24622 F DEBUG : #32 pc 00335a2d /system/lib/libart.so (_ZN3art35InvokeVirtualOrInterfaceWithJValuesERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_jmethodIDP6jvalue+320)
06-18 11:25:47.268 24622 24622 F DEBUG : #33 pc 0026d77d /system/lib/libart.so (_ZN3art3JNI15CallVoidMethodAEP7_JNIEnvP8_jobjectP10_jmethodIDP6jvalue+436)
06-18 11:25:47.268 24622 24622 F DEBUG : #34 pc 00036b4f /data/data/org.vd.visualdj/files/app/_python_bundle/site-packages/jnius/jnius.so
Python クラス (エラーはここにはないようです)
import numpy as np
from jnius import autoclass, PythonJavaClass
from jnius.signatures import java_method
Log = autoclass('android.util.Log')
BaseAudio = autoclass('org.vd.VisualDj.BaseAudio')
base_audio = BaseAudio()
def set_on_data_capture_listener(callback):
Log.d('VisualDj', 'Called set_on_data_capture_listener')
class AudioListener(PythonJavaClass):
__javainterfaces__ = ['android.media.audiofx.Visualizer$OnDataCaptureListener']
@java_method('(Landroid/media/audiofx/Visualizer;[BI)V')
def onWaveFormDataCapture(self, v, bytes, samplingRate):
Log.d('VisualDj', 'Inside wave capture')
try:
y = np.asarray(bytes)
y = y.astype(np.float32)
callback(y)
except IOError:
print('IOError')
@java_method('(Landroid/media/audiofx/Visualizer;[BI)V')
def onFftDataCapture(self, v, bytes, samplingRate):
pass
base_audio.setPlayer(AudioListener())
Java クラス
public class BaseAudio {
protected Visualizer visualizer;
public void setPlayer(OnDataCaptureListener listener) {
Log.d("VisualDj", "setPlayer1"); // This goes well
try{
visualizer = new Visualizer(0); // But this fails
Log.d("VisualDj", "setPlayer0");
visualizer.setCaptureSize(256);
Log.d("VisualDj", "setPlayer2");
visualizer.setDataCaptureListener((OnDataCaptureListener)listener, 12000, true, false);
Log.d("VisualDj", "setPlayer3");
visualizer.setEnabled(true);
Log.d("VisualDj", "setPlayer4");
}
catch(Exception e){
Log.e("VisualDj", "exception", e);
}
}
public void release() {
visualizer.release();
}
}
My Buildozer config:
# (int) Target Android API, should be as high as possible.
android.api = 27
# (int) Minimum API your APK will support.
android.minapi = 21
# (int) Android SDK version to use
android.sdk = 27
# (str) Android NDK version to use
android.ndk = 17c
# (int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi.
android.ndk_api = 21
編集済み
また、上記の Java クラスは、Android Studio を介してデプロイする場合にうまく機能することを忘れていました。