Is it possible to use the Android-framework in a Java-module?

297 Views Asked by At

I am new to Android development. I have the question if and how it is possible to use Android-framework code, like e.g. USBManager in a Java-module in Android-Studio. Or do I have to convert it to something else to do the trick? Cheers David

As I am currently not able to use imports like android.v7.etc..

3

There are 3 best solutions below

0
D. S. On BEST ANSWER

I have found the answer in the android documentation. Java-modules are not meant to use the Android-framework. You must use an Android-library for that (There's also an option to create a Java Library, which builds a traditional JAR file. While a JAR file is useful for many projects— especially when you want to share code with other platforms—it does not allow you to include Android resources or manifest files, which is very useful for code reuse in Android projects. So this guide focuses on creating Android libraries. https://developer.android.com/studio/projects/android-library) Cheers David

3
Astha Garg On

Yes, it's possible to use android specific code in java, when you create any new project using android studio, necessary files are made available to you. To use any android specific library first you need to ensure whether it's directly available to you or you need any additional 3rd party library(that can be imported in app level build.gradle file).

Considering your example of USBManager (package : android.hardware.usb.UsbManager) write 'USBManager' and press Alt+Enter key, this will give you option to import the corresponding class from appropriate package.

If you still find any error, please comment.

0
Ranjan Kumar On

David,

For android application development you can use following 
- Android SDK java classes
- Android NDK 
- Android support library
- native code as jni library(you can write your own native code or create wrapper over existing android framework library)