Cordova - Ignore folders on build - android

I've got a simple app for Phonegap. In the www folder I added some NPM sugar to help development. Now, during the build I'd like to ignore this node_module folder created by NPM when it loads the dependencies. It actually make the build fail.
I've added an ant.properties file within root/platforms/android/ and wrote this line:
aapt.ignore.assets:!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~:<dir>node_*
It prints that it ignores the folder node_modules because of that property, but when I look at the folder root/platforms/android/assets/www I can see the node_modules folder.
I guess my question is, is the folder actually being ignored in the created APK?

Make a copy of your APK and change the file extension from .apk to .zip then extract the zip. You will be able to browse to the www folder and see if it's in there or not.

Related

Copy folder structure containing binaries to native libraries folder

I want to copy and execute some precompiled binaries on device, the problem is that the relative folder structure needs to be the same as in the original package (I cannot move all binaries to root folder).
What so far I found about this is how to copy binaries without .so extension to lib folder here. It works as expected, once installed I can locate the binary using context.getApplicationInfo().nativeLibraryDir, however when I place the directory with binaries it cannot find it using the command.
Further investigation shows that folder does get coppied to apk. I can confirm that by unziping the apk and finding the binaries coppied at /lib/arm64-v8a/.
Now since the apk is fine, the next step I did is check what actually gets copied to device. This can be found in /data/app/app.name.com+random_hash/lib/ and I confirmed that folder does not get copied over, only binaries from root folder do.
What I want to know is whether the code responsible for copying native libraries is located on device and cannot be changed, or the application can be somehow configured to copy the folder structure?
Example repo: https://github.com/D4no0/copy_native_binaries
The code is on device, part of the OS :
"Subdirectory is not supported by the Android OS.
When the APK is installed, the .so libraries are extracted to a directory in the form of /data/app/your.app/lib/. That directory is added to the library path searched by System.loadLibrary so that it can be found. System.loadLibrary do not support a directory structure, thus, the .so files in a subdirectory under lib/ are not extracted."
The above answer is coming from a Googler working on Android, from the following issue :
https://issuetracker.google.com/issues/63707864#comment4
Cheers,
Jérôme

How to add a folder to a android apk use appt and ant

When I use ant tool for build an android project, I do not know how to add custom folders to the apk file, such as a a folder named "running" under the project root, when I use the eclipse can be directly add to apk. I hope you can give me some help, thanks!
During the build process, your Android projects are compiled and packaged into an .apk file, the container for your application binary. It contains all of the information necessary to run your application on a device or emulator, such as compiled .dex files (.class files converted to Dalvik byte code), a binary version of the AndroidManifest.xml file, compiled resources (resources.arsc) and uncompiled resource files for your application.
I can't figure out why you need to add the folder to apk, well if you are asking about adding it in the project and later to be accessed in the apk then yes you can place it inside the "assets" folder of your project

Eclipse: svn:externals in cross-platform Phonegap folder structure?

In Eclipse (on Windows) I created a cross-platform folder structure for Phonegap :
--phonegap_android
--assets
--www (symlink/junction to 'src')
...
--phonegap_ios
...
--src
index.html
Here's what I did to get this working :
created an Android-project in Eclipse based on the phonegap-android
folder.
made a junction for the 'assets/www' folder to link with 'src' (using the Sysinternals command)
created a svn-repository, for this entire project (the parent project that has the different folders for android, ios and src).
I can run the application now, but I have problems committing the project to svn.
The 'www' folder is a junction-folder, so when changes are made to this folder, I want this folder to commit to the real source folder : 'src'.
I tried different approaches :
Setting an svn:ignore on 'assets' to ignore 'www', but then of course
nothing in www is committed, when I commit the android-project in Eclipse.
Setting an svn:externals on 'assets' to define 'www' as an
external to svn://myproject/src, but then it still tries to commit everything in assets/www and I get an error 'No versioned parent directories'.
Any ideas how to get the www folder NOT committed, but at the same time get the src folder to get committed to the svn repository?
Dylan,
Following with svn:externals will work.
Create Folder 'phonegap_android'
Under 'phonegap_android' create folder 'assets'
Commit them to svn repository 'svn://myproject/phonegap_android'
Now for the 'phonegap_android' folder, set the svn:externals as follow
'../src assets/www'(if your svn path for src is at same level as phonegap-android svn://myproject/src which is in your case)
On windows using tortoise svn, it will let you commit 'phonegap_android' folder with svn:external changes.
Take svn updates and you are done.
Henceforth whatever you commit to phonegap_android/asset/www folder, it will be committed to src folder(svn://myproject/src)

Ant build Android project with dependency lib

I have two Android projects, one shared library and the app. Now I want to compile the app with dependency to the library. In Eclipse, it works very well. After that, I upload it via git to my repository and trigger Jenkins to build both projects.
My problem is, that the error occurs: "sdk/android-sdk-linux/tools/ant/build.xml:440: ../shared-lib resolve to a path with no project.properties file for project". That's clear, because in Jenkins the jobs are stored different than under Eclipse.
Another problem is, that Eclipse compiled the shared to ".jar" and Ant compiled it to "classes.jar" (is named in sdk/android-sdk-linux/tools/ant/build.xml).
Ant scripts should allow you to include whatever files you need. In your case I will suggest you move the reference to the shared-lib to local.properties file (this file should also be read by the ant script generated by update-project. Keep the adequate path for jenkins in the repository and modify the file locally for the local built. In the file in the repository you will need to have something like:
android.library.reference.1=../classes.jar
EDIT By the way the suggestion of the second properties file is just because this file is really meant to store location-specific properties.
I fixed it with copy files. The first project builds my shared-lib.jar. The other projects (phone and tablet) copy this file (shared-lib.jar) to there libs-folder and build correctly. But now I have different projects.propertieson the server and my dev-client. This one is not checked in into git.

Android Library assets folder doesn't get copied

I am creating an Android library and it has an assets folder with images.
When I use it in another project the assets doesn't get copied.
Anyone else had this issue?
The new Android Build System that is based on Gradle supports asset folders in library projects!
With ANT based builds it's still not possible:
Library projects cannot include raw assets. (See docs)
But you could
copy the assets manually
or even patch the aapt tool (see http://devmaze.wordpress.com/2011/06/26/enabling-assets-in-android-libraries/)
It is possible to put assets into resulting library jar by small fix:
Put "custom_rules.xml" into you library project home (near the build.xml):
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<target name="-post-compile" if="${project.is.library}">
<echo>Post Compile: add assests from ${asset.absolute.dir} to ${out.library.jar.file}</echo>
<jar destfile="${out.library.jar.file}" update="true">
<zipfileset dir="${asset.absolute.dir}" prefix="assets" excludes="**/*.java ${android.package.excludes}"/>
</jar>
</target>
This will pack your library assets into you resulting library jar. As result, these assets will be included into resulting .apk of your application.
Checked on Android SDK Tools Revision 21.1.0 on OSX
From Eclipse and ANT you can reference the same "assets" folder from multiple projects.
This allows your source tree to have a single copy of the assets files, but have them included in multiple APKs.
See Android: targeted res folders for debugging in eclipse
From ProjectA I was able to reference ..\ProjectA\Assets from ProjectB.
On Eclipse (under Windows at least, I've not tried on Linux yet), I had to create a new variable to reference ..\ProjectA and use that variable in "Linked Folder Location". If I attempted to use ".." in "Linked Folder Location" eclipse wouldn't accept it.
For those using IntelliJ IDEA, you can make a change to your application module's packaging settings to include depedent assets. Note, this was done on version 14.0.2 of IntelliJ Community edition. My main application module now inherits files form my library project's assets folder as if they were right in the main project!
Right click application module > Open Module SEttings. Select Android tree node on module > Packaging Tab. Check "Include assets from dependencies into APK"
Note: I've never used Android Studio, but I would guess there is a similar setting for this in that application.
start by creating android lib project, close after creation. this'll prevert autobuild
use cmd terminal on windows android command is batch file
add tools to path
C:\Users\user_bss>PATH=%PATH%;C:\adt-bundle-windows-x86-20140321\sdk\tools
Generate build.xml for ant
android update project -p C:\Users\user_bss\Documents\Workspace\SDKAdvanced -n SDKAdvanced
notepad custom_rules.xml add the code from above don't forget end tag
run "ant debug" or "ant release" to build
you'll see classes.jar in bin dir this is your packed lib

Categories

Resources