why my App has two manifest files - android

I opened android project in android studio and I found that that project contains two manifest files as shown below in the image.
the first manifest contains the activities in the projects while the other manifest contains the permissions!!
please let me know how that is possible and why??
Note: I used to work with eclipse and I have not seen that feature before
image-,

If you look at the directory structure you see two projects: your app and a library project. So one Manifest-file is for your App and the other is for your the Library-project.

The screenshot you have attached shows that you have been created a project and then added a library file for support. Remove the library if you don't need of that.
Right click on project->Build Path->Configure Build Path->Library
Select that library and remove. Now check your project.

Related

External AndroidManifest.xml doesn't appear under project view pane

I have been developing an Android project using Android Studio and Gradle.
My project's AndroidManifest.xml is located under an external folder.
I'm pointing to it using the following code in the build.gradle file:
sourceSets {
main {
manifest.srcFile '..\\..\\..\\sources\\AndroidManifest.xml'
}
}
Everything works great, the project compiles and runs, except I can't locate the AndroidManifest.xml file under the project structure, when using the project view pane.
Maybe I need to add something else to the build.gradle file?
First - I don't see any reason to maintain manifest outside Android project. It's integral part of Android application so it should be in location where Android Studio can read it. Just copy it where it should be.
If you really need to have AndroidManifest.xml in external location, think about making symbolic link to location where Android Studio expects it to be.
I don't believe you can. When you use the project view pane, Android Studio displays all files in the project root, not all the files linked to your project (to test this, you can create a new file that's not linked to your project in the folder of your project and you'll be able to see it in Android Studio explorer).
Android Studio (and IntelliJ), are build under the assumption that all of your source is in a single "project" folder. That is why the Project view only contains files in the project, it's designed to just show a file tree.
I just tested it, you can use the Android view (one of the other options in the screenshot you posted) to have your external Manifest appear. Some of the functionality is disabled or broken while editing though. This is possible because the Android view is meant to show all relevant source for your project, even if you have the odd requirement of an external manifest.
But please, consider moving it into your project directly or using a symbolic link. You'll be much happier.
Put it in a folder closer to the directory you're on or if needed, move it closer. "..\sources\AndroidManifest.xml"

How to merge an Android application with a library

My question is: How can I merge an Android app with a library? I have only one application left which refers to this library so I want to combine them and get rid of that library.
Are there any "tools" which I could use? Or is possible to merge them "manually" anyway?
The Android Developers Site and Google couldn't help me and my various attempts to fix it by hand failed as well so I'm thankful for any advice or hint.
Create a jar of this library and put it inside the libs/ folder of your application
see if u want create library right click that project->properties->android and tick is library and click apply button. then in your main android app right click project=>properties->android->add and select that library project and goto java build path goto projects and add library project->ok. Now library project is merged with your project.
Right click on project.Select properties->Android.In that go to "Library" section and click on "Add".It will show you the list of libraries available.Select the one you want to merge.

Android: Not able to add Android Library to the Project

I am using Eclipse to develop Android apps. I am importing one example to the Eclipse Workspace. But I am not able to run that project as it does not load the Android library to that project.
Please see this screen shot:
In SlidingDrawer there is Android 2.2 library is added but in SlidingDrawer_Original i am not able to load the android library.
I have cleaned the project and also built the workspace but still the problem is not solved.
if I open the Java file from the SlidingDrawer_Original then it seems like below image:
So What should I have to do to load the Android Library ?
Right click Project properties >Select Android > Select your target AVD
There will be a file called .classpath , just check the Attribute of this file, It must be in read only mode, Change it to Archive Mode and the Clean the Project and set Proper Project Build and try again.
I dont know why it is Happen, But as i come to know, Eclipse always required its properties file. In Some Eclipse it is named as default.properties and in some eclipse it is as project.properties.
I have simply copy paste the default.Properties file and put it in to that project.
Then create the copy of that project in the same Workspace and remove the previous one project.
It solve my Issue. Hope it will also helpful to you.
Enjoy. :)

android library - noclassdeffounderror raised for layouts from the library

I have encountered the following problem:
1) I have a Library ("[x] Is Library" selected) created in Eclipse. It has 2 layouts (main.xml and another one) included.
2) It works very well when I use it within one Eclipse Workspace - I can easily include it in another project and use it without issues.
3) My workspace got huge recently and Eclipse even slower than earlier (and I am working on an Intel Atom "powered" netbook). So I decided to create new one.
4) I have copied the mylibrary.jar file from its bin folder, including the library.jar in new project worked well. Everything compiles, but at runtime an java.lang.NoClassDefFoundError: my.namespace.mylibrary.R$layout is raised at startup.
What I have done:
1) I tried to find solution here on stackoverflow but NoClassDefFoundError on external library project for Android is what I found but I already have the jar file added.
2) Then I have looked into the jar file (renamed to zip & unpacked) to see that the R$layout class is not included there.
How can I get layout classes included into the library.jar file?
Is this really the source of my issue or I am doing something else wrong?
Thanks for advice.
Edit: I have checked and removing xml layouts from the library (e.g. creating a dummy one in code) stops the NoClassDefFoundError. Yet looking at admob.jar file seems it is possible to include R&layout class into the jar file.
I had the same problem. The problem was this line in my derived Activity:
setContentView(R.layout.my_layout);
Eclipse had imported the R from my library project. Problem solved by changing it to import the right R.
Seems the only answer to this one is to create layouts in .java file not in .xml. Tested this one and works well. No idea how admob get theirs layouts included in the .jar file.
To add a library project first make sure that your library project is actually marked as a library project. Right click on the project node --> properties --> Android --> Click the 'Is Library' checkbox --> OK.
Then in your main Android project: Right click the project node --> properties --> Android --> Add --> Select your library project --> OK --> OK

Adding a library/JAR to an Eclipse Android project

This is a two-part question about adding a third-party library (JAR) to an Android project in Eclipse.
The first part of the question is, when I try to add a third-party JAR (library) to my Android project I first get the problem of
Error parsing XML: unbound prefix
because I'm trying to use a class from that JAR (and need the prefix somehow defined). What's going on?
Second, (after fixing that--the answer is given below), my application doesn't work on Android and I discover via the debugger (LogCat) that the class I'm attempting to consume doesn't exist.
Caused by:
java.lang.ClassNotFoundException:
com.github.droidfu.widgets.WebImageView...
Why, when I get no compilation or linker error in Eclipse, does it have this problem on the emulator?
These two questions are rhetorical for I'm going to answer them myself below. Other posts in this forum creep up to the problem and elsewhere there is discussion, but I feel that I can be more explicitly helpful for the next guy to come along.
Now for the missing class problem.
I'm an Eclipse Java EE developer and have been in the habit for many years of adding third-party libraries via the "User Library" mechanism in Build Path. Of course, there are at least 3 ways to add a third-party library, the one I use is the most elegant, in my humble opinion.
This will not work, however, for Android, whose Dalvik "JVM" cannot handle an ordinary Java-compiled class, but must have it converted to a special format. This does not happen when you add a library in the way I'm wont to do it.
Instead, follow the (widely available) instructions for importing the third-party library, then adding it using Build Path (which makes it known to Eclipse for compilation purposes). 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.
What you've done here accomplishes two things:
Includes a Dalvik-converted JAR
in your Android project.
Makes Java definitions available
to Eclipse in order to find the
third-party classes when developing (that is, compiling)
your project's source code.
Ensure that your 3rd party jars are in your projects "libs" folder and they will be put in the .apk when you package your application. You may see runtime errors on the device if something in the jar is not supported, but other than that I have had great success with this.
Setting up a Library Project
A library project is a standard Android project, so you can create a new one in the same way as you would a new application project.
When you are creating the library project, you can select any application name, package, and set other fields as needed, as shown in figure 1.
Next, set the project's properties to indicate that it is a library project:
In the Package Explorer, right-click the library project and select Properties.
In the Properties window, select the "Android" properties group at left and locate the Library properties at right.
Select the "is Library" checkbox and click Apply.
Click OK to close the Properties window.
The new project is now marked as a library project. You can begin moving source code and resources into it, as described in the sections below.
If you are using the ADT version 22, you need to check the android dependencies and android private libraries in the order&Export tab in the project build path
First, the problem of the missing prefix.
If you consume something in your layout file that comes from a third party, you may need to consume its prefix as well, something like "droidfu:" which occurs in several places in the XML construct below:
<com.github.droidfu.widgets.WebImageView android:id="#+id/webimage"
android:layout_width="75dip"
android:layout_height="75dip"
android:background="#CCC"
droidfu:autoLoad="true"
droidfu:imageUrl="http://www.android.com/images/opensourceprojec.gif"
droidfu:progressDrawable="..."
/>
This comes out of the JAR, but you'll also need to add the new "xmlns:droidfu"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:droidfu="http://github.com/droidfu/schema"
...>
or you get the unbound prefix error. For me, this was a failure to copy and paste all of the supplied example from the third-party library's pages.
Error parsing XML: unbound prefix
Resource '/playteddy/res' does not exist.
I got the above two errors and finally I solved it.
Right click your project -> properties -> java build path -> googleadmobadsdk (select and put it top), then you run and problem solved. It is solved my runtime error.
Put the source in a folder outside yourt workspace.
Rightclick in the project-explorer, and select "Import..."
Import the project in your workspace as an Android project.
Try to build it, and make sure it is marked as a library project.
Also make sure it is build with Google API support, if not you will get compile errors.
Then, in right click on your main project in the project explorer.
Select properties, then select Android on the left.
In the library section below, click "Add"..
The mapview-balloons library should now be available to add to your project..
Go to build path in eclipse, then click order and export, then check the library/jar, and then click the up button to move it to the top of the list to compile it first.

Categories

Resources