I just started to play with android dev and java+eclipse is pretty new to me. I managed to create simple project and run it on my device. Now I want to create simple game (more of them actually) and I would love to use shared code base for all of them (game loop, initialization, etc..).
Problem is that I have no idea how to correctly do this. I created android project called engine with all basic stuff that I need and made it work on device. Now I tried to create another project in same workspace called mygame. Main class (activity) of mygame is MyGameApp which inherits from EngineApp (main activity of my engine project) which inherits from Activity.
I added engine project into required projects in mygame build path tab in properties. Problem is that when I try to run this project it crashes on ClassNotFoundException trying to find my MyGameApp class.
Any help (or pointer to some articles that explain how this is done) is greatly appreciated. few hours of googling didn't help much :/
You need to set up an Android Library Project
An Android library project is a development project that holds shared Android source code and resources. Other Android application projects can reference the library project and, at build time, include its compiled sources in their .apk files. Multiple application projects can reference the same library project and any single application project can reference multiple library projects.
The docs go on to say how to convert an existing project to a library project:
You can also convert an existing application project into a library. To do so, simply open the Properties for the project and select the "is Library" checkbox. Other application projects can now reference the existing project as a library project.
Related
I am developing a system where I want to share WCF Service logic between an Android app and an IOS app
I thought the best way of doing this was to create a PCL which I can reference in both
I have shared code which I have packaged up into a shared project.
This is referenced by my PCL. So far so good!
However, as soon as I reference this PCL in my IOS app I get a problem, it appears as though 2 versions of ILocation, one for PCL and one from my actual project.
Am I right in thinking that the only way around this is to have my WCF code in a
I am experimenting with shared projects in Visual Studio 2013
I have an Interface ILocation which is included in my shared project
You just have to move ILocation.cs from SharedProject into Pcl project. Files in SharedProject will still be able to access ILocation type because SharedProject files are actually part of Android and iOS project.
Shared project is nothing more then group of files that are linked(added) into project referencing shared project. This is same as if you would have some folder in your solution folder called SharedFiles and add links to files in this folder from other projects(Android, iOS..). Compiling this projects results into generating new IL(intermediate language code) for each of this projects and types are conflicting. If you ever used common AssemblyInfo.cs and used file linking for this... Well this is same only difference is that you don't have to reference new file in each project but only SharedProject.
So I recently migrated to Android Studio from Eclipse. For the most part, it's better, but I haven't found a good way to maintain a shared codebase between multiple projects.
What I want to do is be able to share some code between several of my applications. Each application is in its own project. From what I've seen, most people add it as a library module in the application's project. The problem with that is the module is accessible from only one project. The other projects within which my other applications reside can't access the library.
It seems to me like there should be a mechanism for creating another library project and then allow each of the application projects to access that code. This worked in Eclipse, where I would create another project in my workspace, mark it as a library, and then have the other projects reference it. I would be able to change the code in the library and then all of the projects referencing it would automatically build with the updated code.
Is this something I could do in Android Studio?
Yes this is possible:
Create the project you would like to have as a shared library - we'll refer to it as sharedProject.
Now in the project that you want to use this library open settings.gradle and paste the following:
include '..:sharedProject:app'
Open your build.gradle and paste the following under the dependencies element:
compile project(':..:sharedProject:app')
You can use this technique for as many projects as you'd like to refer to your common codebase in sharedProject. Note that this assumes your project and your sharedProject directories are in a common workspace directory (which is almost always the case).
I am working on a Android app in which I would like to add plug and play module functionality ,Say I have Two android project
[A] An app for capturing a image using camera and storing it in memory
[B]Enabling map and locate current location .
now I want to add add this functionality in my Another Android app.While going through android developer link and Android Library Projects - Tutorial I figure out that to use plug and play module I have to make my above project as library project so that I can use it in my new app ,now my questions are
1 Is this only way to use library project to add plug and play module
functionally in my app or there are another way also?
2 what are the pros and cons of using library project in order to add
plug and play module functionally?
basically I am researching on how to add plug and play service in my android app and trying to find best solution ,so any clarity on this topic will be extremaly helpful !!!
thanks in advance !!!
An alternative would be to use a linked source folder. In Eclipse, you can set this up in the project settings in the Java Build Path section. You can choose some source code directory outside your project that will virtually be in your project's space (and other projects that use it will do the same). I find this to be handy just from an IDE UI standpoint when I'm co-developing a module along with an app or two. What I don't like about library projects is that they sometimes don't update correctly within your project so you have to rebuild it and your project or clean your project to continue. Also, the module is simpler because it's just a directory of source code files, not an entire Eclipse project.
One other downside of libraries is that they can introduce conflicts that can be a headache to fight. For example, your library might have a different version of the Android compatibility library in it than your main project, and therefore give you compile time errors. Or there are sometimes errors with duplicate libraries, and you have to go fool with the Order and Export settings of your project.
If your module is going to rely on String, layout, and image resources, etc. that are common to all apps that implement the module, then a library project will be easier to work with so you don't have to pass all your resources in through your module's class constructors and duplicate them in each project.
A third option is Gradle, although as far as I know, that would essentially just help automate one of the above two options. I'm not very familiar with Gradle.
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.
I am writing an android library project and trying to test it. I found testing a library project
more difficult than it has to be using my current method.
Right now, I am exporting the library project into jar file. Then I put it into the libs folder of the test project and the test target project. Then I add it to build path of both projects and run the test.
Every time I make a change to the library I have to do this again. Is there easier way to do this?
There is some reference to this in the google docs. Check out http://developer.android.com/tools/projects/index.html#testing
Basically, the easiest way is to write an application that uses the library project and then add unittests to that application.
When creating the tests via eclipse, you can choose to test modules from within your library project. This way, changes to the library project are automatically applied.