I'm using NDK on Android Studio 0.8.9. I've followed this guide where the author is using 0.5.1.
Following his tutorial, he's able to see the generated files into ./app/build/ndk/debug/lib (around time 3:42 in the video).
However, in my case I see there's an extra directory created by Android Studio, called intermediates. Although the NDK generated libraries are subdirectories of intermediates, I don't see them in my project structure. See image below:
This is the content of the intermediates directory itself (seen from an explorer view):
If I add a directory myself with, for instance, only a text file present, then I see that directory under the build directory in the Project structure.
Is there any filtering present that filters out binary files or something like this? Or what could cause this behaviour?
Related
I'm having trouble linking some files to my project. It's an android studio project and I want to link one external file: "Emv_lib.so" (I know that are some questions on how to link .so files, but those are about internal .so files, this is an external one.)
Beside this file, I have an emv_lib.lib and emvIIapi.h (the header file that actually contains the functions that i need to call). I cannot get this to work. I tried with CMakeList, putting the emvIIapi.h file in there, but it comes with the error: "Execution failed for task ':app:configureCMakeDebug'.
C/C++"
I follow some suggestion, to create in src/main the folder jniLibs and put your .so files in there, but it didn't work.
From my undestanding, I have to compile, somehow, either the .so files or the .lib file.
I'm new to android studio, so don't go hard on me. Thank you for your time!
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
I created an App which includes our source code as a native lib (so-file). I'm able to step into it and everything works fine so far with this code.
This native lib links against another native lib which was pre-build on a different machine and which I copied into the jni-abi-folder. I have checked out the svn-repository of this so-file in a different folder parallel to my project and need to be able to debug also into it.
When I now do a break, I can see the method names in the callstack so I assume that the symbols can be loaded, but Android Studio doesn't know where to find the source files.
Under Visual Studio, when I did a break, I could specify the symbols in the symbol path and then an error was displaced that I should navigate to the corresponding source file. Then I only needed to navigate to the folder and it was working.
How can this be done with Android Studio - I have the newest version 3.2.1 installed.
I finally found the solution.
I got a stripped version from my colleague, he basically gave me the version inside his apk which is stripped. Now he gave me directly the build version (I think it is located somewhere in the intermediate directory or so, just search for the name of the lib).
Under Run\Edit Configurations\Debugger\LLDB startup commands the original source directory can be mapped to the source directory on my computer which is different. To achieve this, enter "settings set target.source-map or-dir cur-dir"
There should be a way to find out the original source directory from the so file, but I don't know it right now.
I hope this can help somebody else
This has to be the dumbest question I've had to ask in a while:
How do I add existing C/C++ source headers to the project listing in android studio?
I have a project for android I'm working on, and I'd like to add some header-only libraries to the project. However, I can't for the life of me figure out how to get them into android studio for easier browsing.
I can add C/C++ files by adding them to the corresponding CMake file, but I have no idea how Android Studio decides which header files should be in the application source tree, and it's not finding all the headers I'm actually using.
Frankly, I'm not sure how android studio found the C header files it does show, since they're not listed in any of the project files you're supposed to edit.
Doing a bulk text-search of the entire project directory for one of the headers that are found finds a single mention of the file in the .idea/workspace.xml file, but I experimented adding the additional file headers there, and as soon as I open android studio, it removes the added filename, and it doesn't get shown in the UI anyways.
How the heck are you supposed to do this?
Android Studio 3.0 and lower do not do a good job showing header files in C++. I'm working on improving this for a future release.
Here's how it works today. If Android Studio is given a .cpp or .c file then it will display a .h file that has the exact same base name (if it exists). So if project contains basename.cpp the basename.h will be in the Android view as well.
One way to see all the files in your project is to switch from Android view to Project Files view. This may not be what you're looking for.
In a class belonging to a Library project I call:
webview.loadUrl("file:///android_asset/info.html", null);
Unfortunately, this only works if I duplicate the file info.html into the Application's project asset folder as well.
Is there a way to tell an Android library code: "look for this file in the library's assets folder, not in the application's assets folder" ?
This answer is out of date, the gradle build system and AAR files support assets.
From the Android Docs:
Library projects cannot include raw assets
The tools do not support the use of raw asset files (saved in the assets/ directory) in a library project. Any asset resources used by an application must be stored in the assets/ directory of the application project itself. However, resource files saved in the res/ directory are supported.
If you want to include files from a Library project, you'll need to put it in the resources instead of the assets. If you're trying to load HTML files from your library project into a WebView, this means that you'll have to go a more roundabout method than the usual asset URL. Instead you'll have to read the resource data and use something like loadData.
This is now possible using the Gradle build system.
Testing with Android Studio 0.5.0 and v0.9 of the Android Gradle plugin, I've found that files such as
MyLibProject/src/main/assets/test.html
are correctly packaged in the final application and can be accessed at runtime via the expected URL:
file:///android_asset/test.html
You can achieve this by creating a symbolic link in the project's asset folder that points to the directory in the library project.
Then you can access as below:
webview.loadUrl("file:///android_asset/folder_in_a_libary_project/info.html", null);
Okay. Ive been stressing out and losing sleep about this for a while. Im the type of person that loves API creation, and HATES complicated integration.
There arent many solutions around on the internet, so im quite proud of what Ive discovered with a bit of Eclipse Hackery.
It turns out that when you put a file in the Android Lib's /assets folder. The target apk will capture this and place it on the root of the APK archive. Thus, making general access fail.
This can be resolved by simply creating a Raw Java Library, and placing all assets in there, ie (JAVALIB)/assets/fileX.txt.
You can in turn then include this as a Java Build Path Folder Source in
Project > Properties > Java Build Path > Source > Link Source.
Link Source
Click on Variables. and Add New Variable, ie VAR_NAME_X. location : ../../(relative_path_to_assets_project)
Click Ok
Now, when you build and run your app, the assets folder in the APK will contain your (GLOBAL Library) files as you intended.
No need to reconfigure android internals or nothing. Its all capable within a few clicks of Eclipse.
I confirm that Daniel Grant's approach works for at least the following situation: target project does NOT have an asset folder (or the folder is empty, so you can safely delete it).
I did not setup any variable.
Simply setup a LinkSource as follows (just an example)
Linked folder location: /home/matthew/workspace_moonblink/assetsForAdvocacy/assets
Folder name : assets
The "assetsForAdvocacy" is a Java project, (created with New- Project - Java Project) with empty src folder, and a new folder named "assets", which now provides the entire assets folder for the target project.
This is a fairly straightforward way within Eclipse to provide assets re-use across many different projects IF they do not already have assets, good enough to get going with. I would probably want to enhance it to become a content provider in the long run, but that is a lot more development.
My project accesses the assets with the following code:
String advocacyFolderInAssets = "no_smoking/"; //a folder underneath assets/
String fn =advocacyFolderInAssets+imageFilename;
Bitmap pristineBitmapForAdvocacy = getBitmapFromAsset(context, fn);
I use Motodev Studio 3.1.0 on Ubuntu. It would not let me 'merge' a new assets folder in the new assets-only project onto an existing assets folder in the target project.
If you want to use a setup where multiple derivate products are created from one library you might consider using svn:externals or similar solution in your SCM system. This will also do the trick that static assets like online help may be versioned seperately from the android source code.
I found this older question, it might help you, too.
This is the official way Google uses to archive this (from the above post): Link