Update native library without reinstalling the app - android

I have app which include two native library (for example libfirst.so, libsecond.so). Now a loading libraries standard method.
System.loadLibrary("first");
System.loadLibrary("second");
Now I need to be able to update the library without reinstalling the app (without update .apk).
I can loaded native libraries this method
System.load("/storage/emulated/0/armeabi/libfirst.so");
System.load("/storage/emulated/0/armeabi/libsecond.so");
I think this is a bad practice.
I tried to copy manual the libraries in folder getApplicationInfo().nativeLibraryDir , but system error:
open failed: EACCES (Permission denied)
What are the best practices update native libraries without update apk ?

What are the best practices update native libraries without update apk ?
I don't believe that contingency is covered.
Code signing does two things. First, it ensures the developer who publishes the app is the same one who updates the app. Second, it creates trust relationships between related apps (but that does not apply here). Nikolay Elenkov discusses the topic at Code signing in Android's security model.
If you want to update the dependent libraries, then you need to rebuild the APK to prove you are authorized to make the updates. That's part one of code signing discussed above.
If you want to update a personal copy of the app (and not publish it), then just strip the existing signatures, update the libraries, sign with the Debug signing key, and then push to the device.
Also, you are safe to perform adb install -r <the apk>. -r is "replace existing application", and its effectively a reinstall. It retains the previous application data, like a database.
There are some other things that need to be done when updating an app, like increasing version numbers so its handled properly in Google Play. But they are not really relevant to your question.

There is actually a way to do it
for install your apk:
adb install -r path_to_my_apk.apk
now you can change your code and recompile your .so and when you want to update it you can do:
adb push -p path_to_my_so.so /data/local/tmp/libmyso.so
adb shell cat /data/local/tmp/libmyso.so | run-as com.mycomp.myapp sh -c 'cat > /data/data/com.mycomp.myapp/lldb/libmyso.so; chmod 700 /data/data/com.mycomp.myapp/lldb/libmyso.so'
adb shell rm /data/local/tmp/libmyso.so
Android studio does exactly this in order to install the lldb server when you are debugging native code.
It assumes there is a folder called lldb in your app directory. if you are debugging using Android Studio, this folder will already be there.
Your Java code needs to make sure to load the correct .so using
System.load("/data/data/com.mycomp.myapp/lldb/libmyso.so");
Instead of System.loadLibrary() which doesn't take a full path in a static initialization block somewhere, similar to how you load any other .so
This method can be very useful if your apk is huge and you only want to update the binary for easy debugging.

Related

How can I sign Android application with AOSP certificate

The context of my issue is the following:
I build AOSP for our hardware device on Linux
Together with the system, I build an APK as a system application
Everything works fine in this setup when I flesh it together with system image
However, I would like to have this application build separated from the AOSP build and be able to build it standalone and install from Windows.
On windows, I am trying to build it with Gradle
And the problem arises when I try to push the build to the device the following way:
adb install -r my_app.apk
adb: failed to install my_app.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package <...> signatures do not match the previously installed version; ignoring!]
Obviously the error means that I am missing a platform signature in the application, but where to take it from the AOSP build and how to sign it with Gradle build is not so clear.
Also here I found an advice to uninstall the system app first before installing. Unfortunately, for my case it does not help, the error is still the same even I uninstall it first.
I already spend quite some time on this, searching in the Android make-files for the signing script, but it seems to be not that straight forward there.
Any help would be highly appreciated...
Create a keystore from platform.x509.pem and platform.pk8 files located in build/target/product/security. Then use that with gradle.
See this answer for how to do the conversion: https://stackoverflow.com/a/22214826/3801327
Note: Don't use the default keys included with AOSP, everyone has those, and would be able to make their app a system app in your platform. Generate your own keys.

Signing my android application as system app

In my company, we would want total control for battery consumption in the field, using only 2g and gps could drain the battery awfully fast. What we decided is that we need to have root access to the mobile phone, So that when phone is idle, we would turn off those needless battery consumption.
And also we would not allow users to uninstall it and clear data to it.
My Question is :
Where do I get these signature key?
Is it going to like a root access If ever I successfully managed to
sign it?
What is the difference between Root vs Signed with key?
Answering your three questions:
1 - Where do I get these signature key?
From Android's own documentation in the section Release Keys
The Android tree includes test-keys under
build/target/product/security
But the next part is where you should really pay attention
Since the test-keys are publicly known, anybody can sign their own
.apk files with the same keys, which may allow them to replace or
hijack system apps built into your OS image. For this reason it is
critical to sign any publicly released or deployed Android OS image
with a special set of release-keys that only you have access to.
So basically unless you can somehow gain access to manufacturer's pvt keys it might be difficult to achieve this. This is why a user in a previous comment was saying this is usually achieved by producing your own build.
2 - Is it going to like a root access If ever I successfully managed
to sign it?
You will not get "root access" by doing it, but you will get access to an extremely high level of access. Specifically, what this achieves you is that you will be granted permissions with declared android:protectionLevel="signature" which is, arguably, the most exclusive one.
One other dangerous consequence (or fun, depending on how you look at it) of this is that you can now run your app under system user process android:sharedUserId="android.uid.system" - under android's "process sandboxed" security rules this would normally fail.
3 - What is the difference between Root vs Signed with key?
With an app signed with the platform key from your build, you can get the permissions mentioned above, or run your app with UID 1000 (system uid) which in android is much more powerful than the UIDs of other apps because of the permissions it can request, this is a behaviour specific of Android though.
In a rooted device, you can use UID 0 (root) which has the broadest access in linux based systems, you can bypass most of the security sandboxing/checks/fences on the OS.
Hope this helps ;)
Well below is your answer,
You can find platform keys from
HERE. The command to sign apk (for linux) is:
java -jar signapk.jar -w platform.x509.pem platform.pk8 APPLICATION.apk APPLICATION_sign.apk
onward Android 10 lib64 library path need to provided which can be found at android/out/host/linux-x86 after generating a successful build, one can copy folder or simply provide its path to generate sign APK
java -Djava.library.path="<path to lib64>" -jar signapk.jar -w platform.x509.pem platform.pk8
If you sign your apk with platform keys you won't required root access you can simply install it from "adb install" command, and yes in someway it is like root 'cos it can access all internal api but keep in mind if your app is system signed then you can't write external storage.
First of all don't combine both root is user where system app is application type which distinguish from normal application below link might clear your confusion regarding it.
what-is-the-difference-between-android-user-app-with-root-access-and-a-system-ap
For anyone coming to this question and even after reading the comments not being able to make it work, it might be because there're some things missing (specially if getting OPENSSL errors), here's everything you need.
Sign APK with test keys from the AOSP
git clone https://android.googlesource.com/platform/prebuilts/sdk.git - Careful it's ~6GB, or you can download what you need, the signapk.jar file and the libraries.
download the platform.x509.pem and platform.pk8 from https://github.com/aosp-mirror/platform_build/tree/master/target/product/security (or get your own keys corresponding to the image)
With java installed, change the following command with the right paths for the files, the lib64 in the sdk you just cloned, the signapk.jar file, the platform key files and the apk to sign
java -Xmx2048m -Djava.library.path="~/../sdk/tools/linux/lib64" \ # In the cloned sdk
-jar ~/../sdk/tools/lib/signapk.jar \ # In the cloned sdk
platform.x509.pem platform.pk8 \ # The keys for signing (from step 2)
app-prod-release.apk release.apk # The app to sign and the signed app

Ludei Android App requires unnecessary permissions

I use construct 2 to build my apps and then I export them to CocoonJS which then compiles them as a native app. I download an unsigned .apk file, sign it then upload it Google Play. The apps work great, just like they were natively written.
When I compile my app with CocoonJS it requires all of these permissions that my app doesn't need. How can I remove the unneeded permissions?
Until Ludei implement an optional permissions on their cloud compiler, we have to do a bit of "hacking" to fix the problem ourselves.
Get the attached apktool.zip, extract it to a folder C:\Android (to make it easier later).
https://static3.scirra.net/uploads/articles/1071/apktool.zip
Copy your release CJS compiled game.apk (from herein, referring to that APK file as game.apk) into C:\Android so its in the same folder as the extracted apktool files.
Open command prompt in C:\Android by right clicking somewhere in that folder while holding SHIFT key.
First, we need to install the framework of our CJS compiled game.apk, type this in:
apktool if game.apk
Its instant, with a feedback that it installed in location 127 or thereabouts. Now we have to decompile the APK, type this in:
apktool d game.apk game
It take awhile depending the size of your game & speed of your PC, but all the contents of your game.apk will be decompiled and stored in a subfolder with the same name as your game.apk, ie. game. Note, if you use different versions of apktool, you may need to change the flag to: apktool d game.apk -o game so it decompiles properly.
Browse the new game subfolder, you will see all the contents. What we are after is the AndroidManifest.xml, open it with Notepad++
Hi-res version: halfgeekstudios.files.wordpress.com/2014/07/androidmanifest.jpg
Remove the permissions by deleting the grey highlighted lines!
The permissions ACCESS_NETWORK_STATE & INTERNET are required, if you remove it, your game is likely to crash on startup. This is true even if you have no Ads or IAPs or Social plugins. CJS needs these since its got some built in analytics that require it. BILLING is also required if you implement IAPs. Interestingly, Google has decided that these three aforementioned permissions will now be considered normal and they do not warn users when games have these three only, only if it contains the other permissions!
Here, I'd like to point out this line:
You can edit your game to be on phones or tablets by setting them to false. If you set smallScreens & normalScreens ="false", the game is only compatible with tablets or vice versa (I've tested this with my own games). This is handy if you design your target to tablets and don't want to manually filter over 6,400 devices, one at a time. :D
Once the changes are done, save it. Go back to the command prompt, type this in to recompile it into a new APK:
apktool b game game_new.apk
Takes awhile, but you will get your game_new.apk that is modified. Now you need to proceed with normal signing and zip aligning prior to uploading to Google Play.
https://www.scirra.com/tutorials/1071/removing-permissions-from-cocoonjs-compiled-apk
You cannot remove it. Try other tools like Phonegap. phonegap

How to change apk file and resign it onilne?

For some security reasons I need to change apk file before user can download apk file. But when I change .apk content, my app cant be installed. Its need to be resigned.
So I want to know how do I resign it using only zip-open/read/write operations or something else using php.
The only way I see is to install sdk tools on server and work with them with shell command in php. But I want to know if there are more easy ways to do this
The only way I see is to install sdk tools on server and work with them with shell command in php.
In all likelihood, that is your only option. Even if somehow PHP had a fully-functioning jarsigner embedded in it, it is unlikely to also have zipalign.
Note, though, that by "sdk tools", you only really need the Java SDK (for jarsigner) and the zipalign binary (which, AFAIK, has no other dependencies). You should not need the entire Android SDK.

why won't apk file update

I'm developing an android app using Eclipse. I export the app using the Export Android App function. I sign and align the resulting apk file. I then copy this apk to a webserver and try to install it on my phone. It goes though the installation steps, and when I test the app it does not contain my latest changes. It seems to install one of my previous builds.
Is the problem in:
- the way I create the apk?
- a cache on the phone that has not been cleared?
How do I get Eclispe to make a current apk, and how do I get my phone to install it?
How can I verify which version of my code is in a particular apk file?
Thanks,
Gerry
It could be that Eclipse isn't building the new .apk properly, though it sounds like you're exporting correctly. Are you giving the new .apk a different name from the old one? If not, then you could be downloading or installing the old one by accident.
You should be able to go into Settings -> Applications -> Manage Applications on your phone, then find your app and open its info page. The version string should be listed near the top, so you can verify that the latest version is installed.
Try running "adb logcat | tee logfile" (or adb logcat > logfile) before you begin the install attempt, then ctrl-C it and go over the file with a fine tooth comb - there's likely some hints of the problem buried within the noise.

Categories

Resources