Native Android Application Java Front End - android

I am trying to produce a java front end, via some sort of Android "view" that will allow me to show the console output from a native C/C++ application binary.
I followed the steps from various google searches and I have a tool chain that produces native binarys that I can then "adb push" onto the android device. I can either use the adb shell or a console application like ConnectBot to native to the pushed path and run the binary like so: ./someApplication.
However as I stated in my opening sentence I would like to wrap this binary with a font end producing an apk that can be loaded onto the phone and when it runs it opens up and directs the stdio output from the native binary to the screen.

1) Create android Java project.
2) Place the your library in lib/armeabi folder of the project
3) In your java code loads the library and call exposed JNI calls
An example: http://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-methods-bridging-cc-and-java/

Related

Building Android APK which includes another file that will be ran

I am trying to build a app that after it is installed, will drop another binary that I will execute from within the app. It is basically the command ifconfig but my own version that has some other additions.
Ideally when the single APK file is moved to the device and installed, I would like for the ifconfig file to be dropped in the apps local folder where it will then be used with ProcessBuilder to execute.
Is this something that can be done with Android? The other option would be to download the file but I prefer to have it included with the APK.
You can't quite get that, but you can get the same effect. You can put the file in as an asset, and write the file to the filesystem on first boot of your application. Just check if its already on the filesystem, and if not read it in from assets and write it to the filesystem.
I do question why you're going this route though. Why are you using a C binary rather than writing it in Java/Kotlin? Or using a C library linked via the NDK? Running it via ProcessBuilder is a definite code smell.

Android NativeActivity that references a dynamic library fails to deploy

The environment...
I have a brand new Visual Studio 2015 Android NDK Solution.
This contains 2 projects (the default template code that is generated by visual studio):
A native activity. This is where I want to put Android specific code. It has some default code which fades the screen colour between green and black.
A 'Packaging' project to help with deployment.
I have deployed this successfully to an Intel HAXM virtual device as well as to a real device connected via USB. All good so far.
I then added an Android dynamic library project (.so) - this is where I want to put core code (platform agnostic).
I added a reference to this Core library from the native activity project.
Everything compiles and links fine. I can still create an .APK file.
Other info:
Android SDK 5.1 (Android-22)
Android NDK 21
x86
Clang 3.8
C++ 11
Not using Make files or Gradle
The problem...
Now whenever I deploy to the virtual/real device I get the following error (taken from logcat)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.NATester/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/com.NATester-2/lib/x86/libNATester.so
Things I have tried...
changing the Core library to static (.a)
checked the android device to see if the file exists - it does exist.
Manually deploying the .APK to the android device.
Some articles have suggested using Java code to load the libraries - I want to avoid calling Java code e.g. System.LoadLibrary as this seems like a hack - I feel that it should be possible to to have a pure C++ application on android. I can't be the only person to run into this issue?!
This looks relevant but old and again an unnecessary hack for what must be very common situation
- Can't load native shared library with dependencies in a native activity app
- https://github.com/ikonst/android-dl
For what its worth, I am a seasoned C# developer with Visual Studio (15 years).
I therefore take a lot of things for granted when developing apps - this is my first project using C++/Android and it seems more of a manual battle to get everything to work!
Been struggling for a while but managed to deploy the libraries, quite easy in the end.
Right click on the project [theProject (Andorid-xx)] in the Solution Explorer and select add new item, add your .so library.
Right click on the newly added library and select properties, item type should be library, set Content to Yes, this will deploy the lib.

Why some Errors return while building apk (in Android Studio) although app works?

I get Errors While building apk although App works fine !
I followed Errs and Fixed all Bugs, but wondering why that happened although app works? What is the difference between source-code and apk ?
How Source code run in a device? You have to make it compatible for the device where you are going to run. What error you have seen ?
APK:
APK is a generated Package file which is also called "Android application package (APK) The package is file format used by the Android operating system for distribution and installation of application software and middle ware. More here
Source Code
Source code and object code refer to the "before" and "after" versions of a computer program that is compiled before it is ready to run in a computer. The source code consists of the programming statements that are created by a programmer with a text editor or a visual programming tool and then saved in a file. For example, a programmer using the C language types in a desired sequence of C language statements using a text editor and then saves them as a named file. This file is said to contain the source code. It is now ready to be compiled with a C compiler and the resulting output, the compiled file, is often referred to as object code. The object code file contains a sequence of instructions that the processor can understand but that is difficult for a human to read or modify. For this reason and because even debugged programs often need some later enhancement, the source code is the most permanent form of the program.
More here about source code

Python for Android APK without dependencies

Is it possible to build an APK using Python for Android that doesn't need Python for Android to be there, i.e. it includes Python? If so, how?
I believe this is what you are looking for: https://code.google.com/p/android-python27/
This will embed python into your apk. On first launch it will give you a dialog stating it is "installing". This part will install your script along with an integrated version of python. You are also able to embed different versions of python if you have a preference (2.6, 2.7, & 3.2).
Tutorials to get started are found here: https://code.google.com/p/android-python27/w/list
I think you can use py2exe to convert your programm to an .exe - File and then convert this .exe - File to an .apk - File.

android ndk native executable (not app) write permission

i have a rooted android phone, on which i run native c executables through the adb shell.
I am not using neither Java nor the Java NDK-apps, since i want to do low-level work with this app and no form of interaction with the user.
While everything runs fine, when i try to write a file (i.e. using std::ofstream of fprintf etc), the file is created but it is empty.
For Apps development i know you need to add a line in the Manifest.XML, so that you have write permissions.
Any suggestions for the native executable?

Categories

Resources