assets/ directory not being packaged into .apk from eclipse - android

I have the following directory structure in an app I'm porting to Android (ndk).
Project
/src/ -- Location of my .java
/jni/ -- Location of my Android.mk and Application.mk
/assets/ -- Location where I put my raw data resources
/code/ -- Location of actual c++ src code
The original structure had a "res" directory instead of "assets", but these were just my raw resources, didn't adhere to the android packaging/naming structure, so resulted in errors.
The problem is when I renamed it "assets" the errors in eclipse went away, but the assets were not included in the bin/Project.apk file. When I do aapt l Project.apk, sure enough there is no "assets" items and the apk size is far too small anyway.
So I'm sure I missed a step after renaming the "assets" dir, where I tell eclipse to package these files, but I have no idea what it was. Help appreciated!

I'm using the same structure for one of my apps in Eclipse, with no special references in the manifest. Have you tried a full sweep refresh?
Right-click on the project, select "Refresh"
Select "Project" menu, then "Clean..."
Restart Eclipse
I've occasionally had projects of varying language in Eclipse which required all of the above 3 steps in order to fully update the project files, specifically when I made such changes as renaming folders or added completely new files.

Related

Android - How do I create the assets folder manually?

I'm new to Android development, and I'm trying to manage projects from the command line using the SDK since I cannot get Android Studio 1.2 to work properly in my system (it's unresponsive).
The problem: I created a new project but the asset folder is missing.
Other SO answers (enter link description here) solve this by creating the folder from the IDE, or by pointing to the asset folder in the .iml file, with doesn't work in my case (I trying to mange the projects from the command line entirely)
There's also a solution editing build.gradle, but the project created from command line (using the SDK) doesn't seem to be a gradle project.
Any help would be appreciated.
Just create a directory called "assets" at the root of your project, i.e. in the same directory your AndroidManifest.xml lives. There's no need to "link that folder from the project". At least that's the case on my system, where I'm using Android SDK 24.4.1 (and I'm not using Gradle -- just emacs and ant).
Once I had assets/fonts/aisauc.ttf in there, the following code...
import android.graphics.Typeface;
...
Typeface greek =
Typeface.createFromAsset(getAssets(), "fonts/aisauc.ttf");
mytextfield.setTypeface(greek);
gave me a TextField with characters from the font I wanted.
How do I create the assets folder manually?
You make it the same you make any directory on your filesystem. Whether you use mkdir or a command-line equivalent, or whether you use your desktop OS's file manager, is up to you.
The default location for an assets/ directory is in a sourceset (e.g., src/main/assets/, to go along with src/main/AndroidManifest.xml and src/main/res/ and src/main/java/, where src/main/ is a sourceset). You can have an assets/ directory located elsewhere, if you choose, but then you will need to configure your build.gradle file to teach Gradle the alternative assets/ location for whatever sourceset you are trying to apply it to.
In your left most sidebar or the sidebar that shows the app, manifests, java... etc, right click app > New > Folder (has the green android symbol next to it) > Assets Folder.
On the next screen leave the path as 'main' and click 'Finish'. Then you can drop whatever asset you want into the folder.

Android eclipse project is broken

After switching to my release branch the project had a missing gen file so I added the gen file from java build path.
Now the assets and the res folders are show like gray packages and not folders and I get the errors like res/values/ is missing.
How to return to the standard android project structure in eclipse?
Is there a standard way of returning to the standard Android project. I have become tired to fix project properties and I have tried to clean and restart eclipse It seams that some project metadata is saved the wrong way.
Thanks .
/gen/ folder is automatically generated during compilation. You should include that and /bin/ and also /.properties/ to .gitignore to avoid having to fix properties all the time and also minimise the amount of unnecessary data stored in your repo.

How can it be two AndroidManifest.xml files on a single android project

I learned that in every project we have only 1 AndroidManifest.xml file.
BUT I found two of the same file name !!
One is in the root folder, and the other is in the /bin folder...
How come, and what shell I do ?
thx !
project/bin folder is for compiled (to bytecode) source code and project resources.
Do not worry about it, your IDE is handling content of bin folder automaticly.
When all code is compilled, your IDE (I think, it is Eclipse) can build your project.
When your project builds, it creates a copy of itself for execution in the bin folder.
You can ignore everything in the bin folder as its automatically generated and it doesn't require any edit directly of you.
The only AndroidManifest.xml you have to worry about is the one in your root project directory
One is created by the developer (the one in root folder) and the other one (the one in /bin) is created by eclipse or whatever IDE you are using.
The other one is a compiled binary. This is totally fine. You don't have to do anything. Continue developing!

Android: Source path not being included

In my project I have added some folders that I want included in my project for source files. But no matter what I do, the source never gets recognized. I tried refreshing, clean up, restarting but nothing works. Here is the project's source folder:
I want the folders integration/android added. This is how it is showing up in Eclipse:
And here is what my build configuration looks like:
I could be wrong, but it looks like you have added them as a folder, but not actually added the folder to your project.
The folder should show up in your src folder in the solution explorer window under your other package.
Try creating the package name in your project, then move all the src files into it.
And when its in the src folder, in its correct package, you dont need to include any extra build paths.
(You can have multiple packages in a single application)
Importing someone elses project that is over 2 years old is almost always problematic. I found the easiest solution just to create a fresh project and add the files manually from the old project.

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.)

Categories

Resources