Javah still won't find class files in OSX / Android Studio

帅比萌擦擦* 提交于 2019-12-19 11:42:14

问题


Having referred to --> Javah error while using it in JNI

...and --> android - javah doesn't find my class

...I still can't get javah to work. Specifically...

My java class is located here:

/Users/HKS/Code/MusicPlayer-Android/dspLibrary/src/main/java/com/company/audio/LibDSP.java`

From this folder...

/Users/HKS/Code/MusicPlayer-Android/dspLibrary/src/main/java/`

...I've tried running...

javah com.company.audio.LibDSP
javah -classpath . com.company.audio.LibDSP
javah -classpath /Applications/Android\ Studio.app/sdk/platforms/android-16/android.jar:. -jni com.company.audio.LibDSP

...I've also tried this from within the actual folder containing the .java file...

javah LibDSP
javah -classpath . LibDSP

All give the usual...

error: cannot access com.company.audio.LibDSP
class file for com.company.audio.LibDSP not found
javadoc: error - Class com.company.audio.LibDSP not found.
Error: No classes were specified on the command line.  Try -help.

Any ideas?

Incidental verbose logs show something strange in the search path...

[ Search Path: /System/Library/Java/JavaVirtualMachines....../Contents/Classes/charsets.jar//Applications/Android Studio.app/sdk/platforms/android-16/android.jar:. ]

Notice how there seems to be no separator for the ones added with -classpath. I've tried pre-pending ":" and it makes no difference. I'm assuming this is a bug in the verbose output rather than the core functionality.


回答1:


Got it! It needs the compiled class, not the source. Also, the class folder - ./build/intermediates/classes/debug is hidden from the project in Android Studio.

This is the line that finally worked for me. From my module's root folder (/Users/HKS/Code/MusicPlayer-Android/dspLibrary/):

javah -classpath /Applications/Android\ Studio.app/sdk/platforms/android-16/android.jar:./build/intermediates/classes/debug -jni -d src/main/jni -force com.company.audio.LibDSP

Note the -d flag is the output folder, and -force ensures it overwrites any existing files.



来源:https://stackoverflow.com/questions/26274155/javah-still-wont-find-class-files-in-osx-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!