How to put java property file in apk? - java

I have an android app project that uses an android lib project from third party (don't have source). The "ant clean release" generates the apk and the app runs well.
Now a java property file is added into the lib project, locates under the root of the project folder. Build and install apk, log shows the newly added property file is not loaded. Unzip and dex2jar the apk, cannot see the property file from anywhere. So seems like the property file is not included in the apk build. So my question is how to include the property file into apk, should I do anything extra? Thanks for the help.

If you can configure the location where the 3rd party library reads the config file from, you can put it in res/assets. The files in this directory will be packaged into your .apk file and installed as files in the Android file system.

I had the excact same problem. The solution i found usefull is explained here:
http://www.maxters.net/2012/08/android-source-apk-x-res/
You will have to modify 3 files under build/core, then you can add any file/folder to your apk after updating your Android.mk file.

Related

How to add resource file to Android apk after compilation and build of apk?

Is it possible to add a .class java-class file or if that's not possible a .txt text-file to an APK after it has been built and without source code?
We compile and build an Android application as apk file. And now the customer without needing the development tools has to be able to add at least a custom txt text-file to the APK before installing it on his devices.
The goal is that we write a program that will use the original apk and will add the text file to the apk, so the customer does not need any development tools.
It is not a restriction that the customer does not get the source code but that no additional software shall be installed. Our tool also has to run without installation.
The good news is that an APK file is just a zip file, so it's pretty easy to manipulate files that inside it.
The bad news is that you can add a .class file but Android will not be able to use it... that's because Android uses a different format (Dex) and expects code to be in Dex files instead of plain Java bytecode...
If you wanted to include a custom .txt file then all you'd have to do is copy it to the assets/ directory inside of the APK. Files in this folder are can be extracted to your applications internal folders, so it should be pretty easy to load it directly from there. But don't forget that tinkering with an APK file will invalidate its signature, meaning that you'll have to re-sign that APK in order to install it via an app store.

Android Studio load file from resources

I am trying load .json files from resources so I can use them in unit tests.
I have created a resources file and marked it as a ‘resources root’ directory, and placed my .json files within it. As the files are to be used for tests only, I do not wish to place them in the /res directory as it unnecessarily bloat the app.
I am attempting to open the resources file with the following code, however inputStream returns as null.
InputStream inputStream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("file.json”);
I have set the following in the .iml file that should denote the directory as resources but it seems to have had no effect.
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
Does anyone have any ideas where I maybe going wrong? Thanks in advance!
you can use assest folder or raw folder under resource folder
When the APK file for the app is built, it does not include directories that you create outside of "res" and "asset". Only files inside the APK are deployed to the device or emulator when testing. So there is no way to test a file that you do not include in the APK.
Files that are placed in the tests directory do not seem to be accessible. So AFAIK, you'll have to put the file in the app APK and then remove it later. Or, even better, it is possible to use gradle to produce a version of the app APK for testing and a different one for release. The release version could exclude the file.

How to open Android source code in Eclipse ADT

I am new to Android development and I have downloaded Source code of Cameraapp from Google web site from following locaiton:
https://android.googlesource.com/platform/packages/apps/Camera
I am trying to build and compile it into the Eclipse ADT environment. However when I open the folder using File> Import> Android> select existing project, I do not see the folder being able to be selected as a project.
I also noticed that there is no Android Manifest file inside this folder. How is this possible?
I read somewhere that camera app does not have its own Android Manifest file but it uses manifest file from the Gallery App. Which may be right. But my question is that how can I even compile this application?
Or would I have to compile the entire android application folder? Hopefully that is not the case.
If you do not have manifest file in the project then you have no option than to create an empty android project and copy the corresponding res/ and src/ file to your empty project.
Then modify your manifest file to define your activities and permissions. Then you can build and run your project in your ADT workspace.

JNLP Webstart Launch Issue

I have a requirement to dynamically extract the content of a Jar file to a local directory. Remaining part of application will use these content. Everything working well in my eclipse development environment. However following peace of code returns null when it comes into JNLP launch.
InputStream stream = VLCLibManager.class.getClass().getClassLoader().getSystemResourceAsStream("XXX.jar");
I already did following :
Manifest file of JAR that contains VLCLibManager.class updated with proper class-path entries
My XXX.jar is placed under /lib directory of JNLP. It's getting downloaded correctly
Have the entry (jar href="lib/XXX.jar"/>>) in XYZ.jnlp file
Any help appreciated as I'm stucked with this issue for the past few days.
Finally I resolved the issue. Thought of publishing here as it would help others who face similar issue.
I did below :
I packed resources that I wanted as a Zip file and placed into /resources directory of my maven project
Maven compiler plugin packs this zip file along with resultant jar.
So I can load the zip file to my java code using
YourClass.class.getResourceAsStream("/XXXX.zip")
This loads resources to java program. You can unzip as you wanted and use it whereever needed

Exporting android project to jar (that includes other jars)

I've written a Android Game Engine library and would like to export it to a jar file. I've tried to do this with the following:
export > Jar File > Finish
As soon as I add the jar to the build path of another Android project, I get a little box in my code saying:
The type foo cannot be resolved. It is indirectly
referenced from required .class files
I believe this is because my Game Engine library includes other libraries in forms of jars.
How can I add those jar files to my Game Engine jar file?
You can decompile the other jar file using JDui, take what you need, and add it to your library. It all depends on how big is what you need..
Also, check whether you are using proguard in the export. You would have to be careful on how to configure it.
I assuming you are using Eclipse. You also need to use Properties->Java Build Path->Libraries->Add Jar button to add your jar file to the target project

Categories

Resources