i want to merge two different android projects to use the functionalty of both in one project.
They are using complete different packages for the files.
I copied the files with the different packages in one project, but there is a problem with the manifest file.
Is it possibly to have different packages in the android manifest file?
Or how can i solve this? Maybe specify the activities with the whole package and not use ".shortcut" ?
I hope there is someone to help me.
Thanks!
Building a library can solve this problem. This is the way I have proceeded on my side for a similar question:
I had a project ProjectA that was finished and working
I had a new project ProjectB that had to reuse some functions of ProjectA.
These functions were likely to be reused again so I built a library Library1 and I moved the necessary code from ProjectA to it. I set the Library1's isLibrary flag to true under Eclipse (that's in the project properties - let me know whether you would like more details on this and I'll edit that post if needed).
Then I modified the ProjectA's properties to use Library1. This also implied some refactoring on ProjectA side but that was OK.
And finally, I created my ProjectB as a client of Library1 as well. And this was straightforward.
There is no easy way to merge multiple projects into one. However, you can choose to build one of the projects as a library and import it into the other.
See working with library projects
you can merge the code if it not having large scope..ie not having Native library and etc...
for merging the project you need to refactor package name, layout xml and etc...
for example. main.xml are seperate for both of package so need to care of such things
Related
I have an Android Studio project
which consists of a login activity with relative style, manifest, IntentService and other stuff.
I want to insert this little project in many other apps, what is the best way to proceed ?
Is Module the right way ?
The ultimate goal is still to easy maintenance, such as if one day the server should change URL, I would not have to make changes in any application that uses this login activity :-)
You need to extract these components in a separate module:
A module is a discrete unit of functionality which you can compile,
run, test and debug independently.
Modules contain everything that is required for their specific tasks:
source code, build scripts, unit tests, deployment descriptors, and
documentation. However, modules exist and are functional only in the
context of a project.
Then, include that module in all projects using it.
In fact, you can create the module in an independent "library" project of its own. And add it as a dependency for all projects using it.
Going a step further, you can publish the output of an open source library project as .aar or .jar on maven central, jcenter and other public repositories. Then other people will also be able to use your module.
Some important points to remember when creating android library projects:
The resources (strings, layouts, xmls, images) of a library will be merged with those of final project on build. Still your module's R class will stay under your module's package name.
Some attributes from manifest file of library might be merged to that of final project (like that of <application> ). So, a library module should have a minimal manifest file, with at most, the package name.
You may include an example application project inside a library module, but do not redestribute the example app project with library. It will cause trouble for someone building an application using your library.
I think that what you need to do is to export your original project first:
File>>Export
Then go to your new project and import the original one.
Dont forget to amend the setContentView() method to point to your original activity(the one you imported)
and finally dont forget your intent method!
if you have any issues let me know and i will create a detailed answer for you but i think that you will be ok!
I'm working with eclipse mars on ubuntu 15.04.
I'm trying to do the tutorial about volley (https://developer.android.com/training/volley/simple.html) but I'm facing some difficulties.
As explained in this tutorial, I've cloned the volley repository, created an android projet for it, marqued it as a library. I can see that ./src/main/bin/volley.jar is generated, so at that point I would say that everything is good.
Next, I created an Application project and in Projet>Properties>Android I've added volley as a library.
If I well understand the tutorial and some other answers about similar questions I've read, this is the correct way to go.
Anyway, in my code if I try some "import com.android.volley;" I always get the same "The import com.android.volley cannot be resolved".
The only way I can make it work is by adding the source code of volley into my project directly. Obviouly this is not the good solution.
Can someone please tell me what I'm doing wrong ?
Regards
EDIT1:
Thank for the comments but it appears to me that those information are a little bit out of date. If I refer to the git history, volley switched from Gradle to Maven 8 months ago, so it does not build with ant.
Any way, as I said in my question, the project is already building within eclipse so that I have a volley.jar. So I try what is suggested: copie the volley.jar into the libs folder on my project. I'm surprised it does not work :/ Looking closely to the jar file I'm surprised it weighs only 166 bytes!
Referring to https://developer.android.com/tools/projects/projects-eclipse.html:
Creating the manifest file: A library project's manifest file
must declare all of the shared components that it includes, just as
would a standard Android application
and
Declaring library components in the manifest file: In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any <activity>, <service>, <receiver>, <provider>, and so on, as well as <permission>, <uses-library>, and similar elements.
Declarations should reference the library components by their fully-qualified package names, where appropriate.
May it happen that the default manifest file from volley is incorrect and it does not "export" anything which makes the jar file being so small?
Does it mean that I have to put in both manifests (the one from volley and the one of my app) any import I did in my code?
What is the best way to create an Android project and duplicate it?
I would like to have projects that inherit a class that is responsible for the configurations and the base project to bug fixes and improvements.
Another problem that comes to mind is the design that some projects may change, for that matter should be able to add in my project resource folder that inherits the resources to change.
Thank you very much!
As for the duplication of project: you can easily copy-paste the whole project's structure and then from Eclipse you can do New Project -> Android Project -> create project from existing source.
What you are actually asking about, if I am not wrong, is Android Library project. This is a project that you can use to add on the source of other projects. You can read about android library projects here and in the linked page here.
I would use github fork system for inheriting projects and files. Take a look at github, create an account. Moreover, there is google code and tortoise svn alternative.
I am currently working on a Android Project where we are expected to merge our App with 2 more apps from vendors who wouldn't be sharing their code.So just wanted to know Is there any way we could just include there Source code as JAR Files in our project and then include their resources and point to them(I did do it using getResources().getIdentifier("splash", "layout", getPackageName()) But Its still not working ?? I think I have tried all possible methods so hoping you guys could help me with this.
To quote CommonsWare from this question:
Bear in mind that your packaged classes cannot reference resources (at
least not via R. syntax), and that JARs cannot package resources,
manifest entries, etc. If all you are trying to JAR up is pure Java
code (perhaps using Android APIs), then you should be fine.
Basically, you can only use JARs that contain pure java as libraries in your app, not entire other projects.
The Activities can be compiled into a jar and added to the main Android project and we need to add their project's resources into your Project. The only we could make it work is using the getResources().getIdentifier("splash", "layout", getPackageName()). Even the Widgets like TextView, Button and all those should be referred to using the getResources() method. Like, for example, If you want to perform a action on particular button then we need to identify them by getResources().getIdentifier("Button" /*id in the XML File*/, "id"/*type*/, getPackageName()).
One more thing: you need to specify all the Activities in your Main Android Project's AndroidManifest.xml file with their package name. I hope this solves something.
In order to support faster build times, the r16 tools are creating their own jar files inside of Android Library Projects. You can use this feature to solve this issue. If a vendor would like to release their Android Library Project but without source code, they can make a copy of that Android Library Project that contains everything except for the source code tree. Next, include the jar file from the original Android Library Porject (the one that the r16 tools built.) This will allow you to have a component you can distribute that does not require source code. The consumer of this new Android Library Project will need to manually add any necessary meta data to their own project's AndroidManifest.xml file as needed (Activities, Providers, Permissions, etc).
I have an Android code base which uses APIs with settings to get different data for several apps. All apps use the same code base but with one or two design tweaks. So how do I re-use the main code base without having to copy the whole Android project each time?
iPhone uses multiple targets in the same project which works well. If android cant do this do I need to compile binaries of the code base in one project and then import into each new app project? If so how? I'm using Eclipse and am an intermediate Java developer.
Any help much appreciated!
Doug
Check out "Working With Library Projects" from the Android documentation. This should be just what you're looking for: http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject
The current way to approach this issue if you are using Android Studio with Gradle is by using Gradle, Build Type + Product Flavor
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
Build Variants
One goal of the new build system is to enable creating different versions of the same application.
There are two main use cases:
Different versions of the same application
For instance, a free/demo version vs the “pro” paid application.
Same application packaged differently for multi-apk in Google Play Store.
This new concept is designed to help when the differences are very minimum. If the answer to “Is this the same application?” is yes, then this is probably the way to go over Library Projects.
Note: This answer is basically obsolete now that one can create .aar libraries with resources. It still works, though, and there may be times when the portability of a .jar is desirable, so I'm leaving it here.
Blumer's answer is a good one, and you should definitely look into Android's idea of library projects. However, there is another alternative. If you have a module that contains only Java code, but no resources of any kind (images, layouts, etc.), you can compile it to a .jar file separately and use the resulting .jar in multiple application projects. It works like this:
Create a new Java project in Eclipse (not an Android project) and move the source code of your module there.
If your module references any classes from the SDK, you'll need to add the Android SDK .jar to the project's classpath (Project > Properties > Java Build Path > Libraries > Add JAR).
When your module is ready to use, bundle up its .class files into a .jar. You can do this manually, or you can look around to figure out how to get Eclipse to do it for you.
Copy your module .jar file into the "libs" directory of your app's main project.
Add the module .jar to the project's classpath (again, Project > Properties > Java Build Path > Libraries > Add JAR).
Now you should be able to build multiple apps using the same .jar, while maintaining only one copy of the module's source code.
Depending on your particular situation, this may or may not work any better for you than the standard Android library mechanism. But it's worth considering as an alternative.
The Android documentation recommends another approach if there aren't too many "different APIs" used.
The idea is to use reflection instead of making direction references to the code. Make sure to use optimized reflection instead of lookups every time.
References
http://developer.android.com/training/multiple-apks/api.html
http://developer.android.com/google/play/publishing/multiple-apks.html#ApiLevelOptions
You might want to consider using a source control system like Subversion (or GIT). Keep your most feature complete version in the trunk, and make branches for your separate versions that use different data sources or require minor layout changes, etc.