Hi I'm quite new at Android programming, and I am working on a project, which contain classic java part and Android part, and I need to share some classes between these 2 subprojects. I solved it that I have other project, where are the shared classes.
Is this the best way ? Or is there better solution ?
Related
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..
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.
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)
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
I followed this "tutorial" here and loved the idea of splitting up an Android project into modules. But now I stumble upon problems I wouldn't have otherwise, e.g. that I can't use SQLiteOpenHelper in the model-module as it's plain Java and not Android.
Is there a way to use Android-Classes (e.g. SQLiteOpenHelper) there nevertheless or is it recommended not to split up the app at all?
When you create a new Module in Android Studio you can choose which type on Module you want to create. Just choose Android Library and you will have access to the Android classes
I am building a new project which uses some Java class from my other projects. I just found a bug in one of my file and I have to fix it everywhere.
Is there a way or best practices to solve this issue.
I have now these projects:
Project A (game)
Project B (game)
Project C (tutorial app)
in each projects I have these common classes:
Settings.java
Progress.java
Now I copy these files to each projects. All these files are identical and other than the bug I just found, I do not have to change them.
Thanks
How about making your own Android Library Project and linking to it from the projects where you are willing to use it.
Here, take a look. Explanation of different kind of projects you can create.
I am building series of android projects with almost the same classes, only some sources like images are different.
I want to make it like a source or library, so that I can create projects by only referring to that source/library, inherit the class, and put in images.
For example, I create a project call "Prototype", which is the template. Then I build new projects, adding "Prototype" in Build Path -> projects. Then I extend the classes in "Prototype", it compiles. But when I run it, it says "Could not find Prototype.apk!"
Am I doing correctly? Or I need the Prototype.apk? If so, where should I put it?
Are you using Eclipse as the IDE for your Android projects? If so, you can create library projects as described in: http://developer.android.com/tools/projects/projects-eclipse.html
You can then use a library project as your Prototype.
Android resources and their automatically generated references simplify the development of one app a great deal. But they also complicate the reuse of Android activities in multiple projects, and in general of any component that uses resources.
Library projects are a limited alternative. A project can depend on many library projects, but a library project can't depend on another, and adding additional JAR dependencies is not straightforward.
How do you reuse Android components (not plain old Java code)? Any tips and tricks?
I have some tips, tricks, and tools wrapped up in the Android Parcel Project.