R cannot be resolved into a variable when integrating two packages - android

i try to integrate Twitter project to Facebook project by copying and paste all the relevant files and clean the integration project. However, in the GEN file(R.java and BuildConfig.java) the twitter packages is deleted. it seems like the GEN file can only be generated for one packages in SRC.

Correct, there is just one R file. You have several options though. You probably could leave the Twitter and Facebook in their individual projects (instead of copying them into your project), and add them via the Android Library system. Or, you would need to copy all the class files, plus all the resource files and any other required files. (I expect that the resource files weren't copied, and thus not included in the project R file).
Personally, I'd recommend the first method. Just add each project (Twitter and Facebook) to Eclipse. Then right-click and select Properties. Choose the Android section, and in the lower half of the panel, check "Is Library". In your project, right-click on it and select Properties, then Android. In the lower half, (same location as the "Is Library") select Add and add your Twitter and Facebook projects. That should include them in the build for your project, including any R files they might have!
Update (Activities in Library projects):
Check the "Declaring library components in the manifest file" section of the Library section. Essentially, you'll need to declare all the Activities, etc, in YOUR project's manifest. You'd still link the libraries as described. (There's also a more detailed explanation of how to configure the libraries at that link as well!)

Related

Open source License in Android App

We have an android application and are using some third party licenses. What is the best place to include these licenses in the app? In iOS we include it in the setting bundle, but I am not sure the best place to do so in android.
Thanks for you help
For my apps I generally place the license .txt file in the assets directory. Read the Github (I generally use library from github) page thoroughly about licencing. Notify the original creator about the use of his library. Then, if the product is of a client I will ask if to include the creator with link in the about section(if there is one). In my own apps I will include the link and author in the about section somewhere in my app.
Here is the step-by-step:
Download the library to your host development system.
Create a new folder, libs, in your Eclipse/Android project.
Right-click libs and choose Import -> General -> File System, then
Next, Browse in the filesystem to find the library's parent directory
(i.e.: where you downloaded it to).
Click OK, then click the directory name (not the checkbox) in the
left pane, then check the relevant JAR in the right pane. This puts
the library into your project (physically).
Right-click on your project, choose Build Path -> Configure Build
Path, then click the Libraries tab, then Add JARs..., navigate to
your new JAR in the libs directory and add it. (This, incidentally,
is the moment at which your new JAR is converted for use on Android.)
NOTE
Step 5 may not be needed, if the lib is already included in your build path. Just ensure that its existence first before adding it.
This is also explained at adding-a-library-jar-to-an-eclipse-android-project.

How to include external libs in Android source controlled project?

How should external libraries be included into Android projects?
I see this documentation from Google:
http://developer.android.com/tools/support-library/setup.html#libs-with-res
...which says they should be kept outside the source tree for the project, and referenced as dependencies.
The guide for Facebook libraries says the same thing:
https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/
What about when the project is going into source control, and will be worked on by multiple developers? Is it possible to be sure other developers will have the correct versions of libraries if they're not included in source control?
It seems as though it might be better to check in the whole tree of these external libraries under say an "external" folder in the project and then reference them as libraries from there? The above links don't say this is wrong, but is there any reason not to do that?
I could not find anything against this approach, but maybe my search skills are off.
Thanks!
You have basically tree options (referring to git):
Putting the source or binaries into your git repository.
You can create/clone extra repositories and link these as submodule into your main repository.
Use gradle/android-studio to maintain remote binary dependencies.
In my opinion, option 3. is the best. It speeds up build time and reduces the date saved in your internal repository. Referencing most open source projects, googles libraries and even the Facebook API is just a one liner in your build.gradle file.
For internal libraries or anything not uploaded to some maven repository, you can create a local maven repository and link that.
And in the end, you have the option 2. to create a library submodule within git and gradle to handle it efficiently.
If you want to stick to eclipse + ant, try 2. first.
At least ant will work out of the box for building all things.
Setting up eclipse is a bit more difficult but can be done.
Option 1. is easy to implement, but It might get messy at some point.
Copy jar file in android project libs forlder and right click on jar file and click on bulid path-> add to build path.
If you want to add jar file then copy your jar file and put in to libs folder, and if you want to add external library then import your library project go to project properties and select android tab and add external library with add button.

Creating jar Library of Android project?

I have a project that uses some resources.I want to create a library from it and publish it.I create a jar file with export option of eclipse,but it did not work.Then I search the we b and it seems that way works if and only if project does not use resources.But I saw this post.Here CommonsWare saya there is a way to create a jar file from a project that uses resources.But that answer has two link that do not open any page on the web and I could not test CommonsWare's answer.So my question is:
Is there any way to create jar library file from project that uses resources?
Note:
I read docs that say:
If you have source code and resources that are common to multiple
Android projects, you can move them to a library project so that it is
easier to maintain across applications and versions.
But as I said before,I want to publish my jar and docs say we can not create jar file from library project.And so I can not publish it.
Here CommonsWare saya there is a way to create a jar file from a project that uses resources.
Not in that answer. You can tell that by actually reading the answer.
But that answer has two link that do not open any page on the web
Sorry, Google reorganized their site and broke the original links. The answer has been updated with current links.
Is there any way to create jar library file from project that uses resources?
No.
You can create an Android library project that includes a JAR instead of Java source code. AFAIK, this recipe still works:
Create an Android library project, with your source code, resources, and such, and get it working
Compile the Java source (e.g., via Ant) and turn it into a JAR file
Create a copy of your original Android library project to serve as a distribution Android library project
Place the compiled JAR from step #2 and put it in libs/ of the distribution library project from step #3.
Delete everything in src/ of the distribution library project (but leave the now-empty src/ directory there)
Distribute the distribution library project (e.g., ZIP it up)
And the new Gradle-based build system supports the AAR package for distributing libraries and such, though I have not played with this yet.

How to include library projects

I have a working app and now wish to include an advertising system by mopub. Looking at their getting started guide it says I should fist extract a "library project" (I'm not even sure what that is) using git. After having done that I now see that I have a directory called mopub-android-sdk inside this directory are a tree of further files and subdirectories.
The guide then states "Make sure the Android SDK files are in the same parent folder as your project"... this is where I'm confused. I have all my source files, androidmanifest etc in a directory c:\android\mygame am I now supposed to put mopub-android-sdk and all its sub-tree inside c:\android? or inside c:\android\mygame? (or somewhere else?)
EDIT: Some answers/comments have discussed the idea of converting the library project into a .jar file and then putting that in my libs directory... I have no objection to this so long as someone tells me there are no disadvantages to this compared to not making a jar - thinking about it more, wouldn't the jar have to include every single function, whereas if I left it as a library project, the compiler may be able to omit unused code?
EDIT: Now I am getting more sceptical about the make-jar-then-put-in-libs approach. I found mopub-android-sdk.jar in the bin\res directory and copied it to my projects libs directory. The ad system seemed to work fine, except in the location on screen where I expect to see a specific icon (to dismiss the full screen ad) there is a junk image. I noticed that amongst the tree of files beneath mopub-android-sdk there is a res directory containing png files. I suspect that these images are not in the jar file.
If you're simply including a *.jar library, put it in the libs/ folder of your project.
If you're trying to include an entire project...
Right click the project you want it to be included into and go to properties. On the left side where there are tabs, select "Android". In the area that says "Library" press the "Add..." button and then select the project you want to include. Do a clean build of your project.
Download the library to your host development system.
Create a new folder, libs, in your Eclipse/Android project.
Right-click libs and choose Import -> General -> File System, then Next, Browse in the filesystem to find the library's parent directory (i.e.: where you downloaded it to).
Click OK, then click the directory name (not the checkbox) in the left pane, then check the relevant JAR in the right pane. This puts the library into your project (physically).
Right-click on your project, choose Build Path -> Configure Build Path, then click the Libraries tab, then Add JARs..., navigate to your new JAR in the libs directory and add it. (This, incidentally, is the moment at which your new JAR is converted for use on Android.)

What does checking the "is Library" checkbox do "Under the Cover"?

I noticed that when I convert an existing Android Application project to an Android Library project by checking the "is Library" checkbox, nothing changes in the project's source code or XML files.
So what really happens when the "is Library" checkbox is checked? What changes internally, in the package and/or project files? Where can I learn more about this?
To better explain my question:
What I am interested to know (mainly
for troubleshooting purposes) is
what differentiates an Application package from a Library
package "under the cover"?
Is the fact that a project is
"Library Project" marked
somewhere? If so, where does it
mark it (obviously not in the source
files and not even in the res XML
files)
From the Managing Projects from the Command Line page:
The create lib-project command creates
a standard project structure that
includes preset property that
indicates to the build system that the
project is a library. It does this by
adding this line to the project's
default.properties file:
android.library=true
In other words, it's a property that is utilized by the build system and not by the operating system.
UPDATE: I'm on my iPhone so I won't type out a whole paraphrase, but here's a pretty good blog article discussing the differences between a Java JAR and an Android Library Project, including how the dex tools add the resources and dex code to the .apk:
http://devmaze.wordpress.com/2011/05/22/android-application-android-libraries-and-jar-libraries/
From the devsite: http://developer.android.com/guide/developing/projects/projects-eclipse.html
You can also designate an Android
project as a library project, which
allows it to be shared with other
projects that depend on it. Once an
Android project is designated as a
library project, it cannot be
installed onto a device.
A library project isn't packaged as a seperate redistributable file as you're used to with a jar. It's merged with the the apk file of your application.
The page you linked to mentions it in the Referencing a library project section.
As soon as the Properties dialog closes, Eclipse rebuilds the project, including the contents of the library project.

Categories

Resources