How can I restore Nativescript application code from android device? - android

When I create an APK while developing a Nativescript application, Nativescript stores all the application code in the generated APK file, and that helps me a lot in case something bad happened to the code[The code was deleted, Didn't commit changes I was working on for a long time,...]. When something bad happens to the code, I usually generate an APK from my android device using any APK Extractor tool and decompile it with JADX to obtain my original code and save my day.
Nativescript doesn't generate NEW APKs when I make changes to layout or js files[even though changes are applied on the android device]. Nativescript generates new APKs only when I build the project. and that doesn't help a lot when I need to restore my code after a lot of changes on it.
We're working on a nativescript application. We've been making changes on the application for about two days without generating new APK nor committing changes to git. The files where suddenly removed from pc and we don't know why.
We extracted an APK from the latest working version on the test android device, decompiled it and retrieved the code but the changes of the last two days weren't there.
Is there a way to restore the code from a Nativescript application installed on android devices? By restoring the code I mean even restore all the changes on the code after building the application.
Where/How does nativescript store the instant changes on the code for my application on the android device?

You can view your code by accessing the application data from adb.
connect to your application from adb
adb shell run-as org.nativescript.myapplication
and you can find your files in this directory
/data/data/org.nativescript.myapplication/files/app

It's not wise to depend on your APK for retaining your source code, you should probably use a Version Control System like Git, may be services like Github / BitBucket / GitLab etc., to maintain your source code.
While using a Version Control System, you should commit your changes regularly. That's the whole purpose here, even if you are not sure about your changes you can still use your own branch and keep the changes committed and merge to main branch only when it's fully ready.
I guess you are not using the --bundle option while you run / build the app which is recommended to keep your application lightweight at same time provides a minimal obfuscation using Uglify. With next major release of NativeScript this --bundle option will be marked as default, so you will no longer be able to extract your exact source code at all.
Also think if someone wants to hack your app while you haven't followed any obfuscation, it's easy to clone your work Or break the functionality as they wish. Learn more about securing your source code here.
Still regarding where the live changes are being stored, I think it will be within application data directory on Android.

Related

Elegant classes loading and updating system

In the current state of the project I'm currently working on, I have a classic Android Studio project with a classic app on it.
For some good reasons (it's an embedded app), I would like to include an auto-update feature in the app, which doesn't require to exit it (I must stay inside the app or another app and never show the underlying Android system).
I have two solutions to do this :
Create another "updater" app which updates the app using the package manager command. It requires a rooted device to work, but it would suit my needs : when an update is available, the main app closes itself and opens the updater app which updates the main app and starts it back
Have the actual code of the application stored to the external storage and turn the APK into a bootstraper which downloads and runs the app
The later solution is the better one since it doesn't require a rooted device.
This is why I would like to write an elegant system to achieve this ; the development of the app should not be crippled by this (e.g. I don't have to upload the new classes at each build, I don't need to do extra voodoo work to add activities or permissions to the manifest...).
I thought of using the build variants of Android Studio :
Debug variant : build the app like usual, don't use the bootstraper
Release variant : don't include all the classes in the APK, build an external JAR which contains them and use the boostraper in launcher intent
I saw how to load external classes from the external storage, but I couldn't find anything on how to externalize the whole app code, including activities. I have the feeling that we just can't.
Would such a system be possible to develop ?

Take test app from android studio off of phone for use.

I recently deleted what I had in terms of an app from Android Studio due to ridiculously bad code. But, I had originally tested the app before the code went crazy. With that being said, I have that part of the app on my phone. Can I take the app off of my phone and put it into Android Studio and pick up where I left off on that? I've read that you can take an .apk and load it into Android Studio, I just don't know where to find it on my phone.
You can decompile the .apk, but you can NOT turn it into an Android Studio project. And if you enabled proguard when building, the decompiled .java files will be a jibberish.
What you should do is install a VCS like git (it is easy to setup and use) and commit your changes regularly. This way you will always be able to roll the project back in case of trouble.
In order to get access to the .apk file, you need to use a 3rd party app like appsaver or super saver to save the apk onto your sdcard or internal memory.

BackgroundFetch / Background running app using PhoneGap Build

OK I have done a lot of research over the last few days, reading a lot of posts on here. I have build an app that using the accelerometer and geo-location.
Now thanks in part to many different posts on here and other sites I have got most of my app working without any problems.
I now have to get it working as a background app. I am building this for iOS and android, but the main aim is iOS. I know that iOS7 changed a few things but also add support for BackgroundFetch, how do I use that within a app that I will be building with build.phonegap.com?
Now I have found this plugin, de.appplant.cordova.plugin.background-mode but when I added it to the config.xml file, phonegap build says its unsupported?
I know there is a list of areas, What's solution to make task background in iOS same service in Android? , where you can list in your 'plist file' for iOS and state what type of application it is and iOS will run it in the background because its using one of these features.
Now I have read somewhere - not to sure where - that the config.xml is built, when phonegap build runs into the plist file, so somewhere in that file I should be able to state that it is application using this and that, therefore run in the background?
So is there any many of making my app run in the background?
Any help would be most welcome
Thanks
Glenn.
The resources you have found are referring to building apps locally on your machine, not with phonegap build. You will not be able to achieve the functionality you are looking for with PGBuild as they don't allow that level of configuration.
To achieve this you will need to setup a local cordova/phonegap client and build your app from your computer.

Developing customized version of built-in SMS/MMS Android Application

Okay, here's the situation:
I'm developing an application for a client (or trying to do so). It requires much (if not all) of the same functionality as the built-in SMS/MMS application. So, I thought - HEY! Android is open source right? I can take the application and modify to my needs, right?
So, I found the code on github for the MMS/SMS application (for some reason, based on the AndroidManifest file, it calls my project I built, "ConversationList"). But I get TONS of errors involving the import com.google.android.mms.* package and a couple other packages.
Everyone keeps saying "it's a private/internal package", and "download the entire AOSP". But, HOW do I do this on Windows, and WHY can't I just download the appropriate packages to use in the program?
ALL I want to do is build a project in Eclipse deploy it to my phone, and then modify the necessary code. If Android is open source, why so many secret/internal packages? This is frustrating.
Any advice?
So, I found the code on github for the MMS/SMS application (for some reason, based on the AndroidManifest file, it calls my project I built, "ConversationList"). But I get TONS of errors involving the import com.google.android.mms.* package and a couple other packages.
AOSP applications like this are designed to be built as part of a firmware image, not as standalone apps.
But, HOW do I do this on Windows
Most likely, you don't. Cygwin might work. More likely, you will need to use OS X or Linux, such as running Linux in VirtualBox. And the result of your build will not run on anything, except as part of a firmware build that you use to replace the firmware on a device.
WHY can't I just download the appropriate packages to use in the program?
Because that application is designed to be built as part of a firmware image, not as a standalone app.
ALL I want to do is build a project in Eclipse deploy it to my phone, and then modify the necessary code.
Then find a project that is designed to be built as a standalone app as your starting point. Or, work on modifying the project you are trying to use to work as a standalone app, by ripping out all the functionality that depends upon things that are not in the app itself.
If Android is open source, why so many secret/internal packages?
They are not "secret". They are part of the firmware.
For example -- since you appear to be familiar with Windows -- it is entirely possible that "apps" like Control Panel are not designed to be built independently from the Windows OS. If you were able to download the source code to Windows and tried to load Control Panel into Visual Studio, it is eminently possible that you could not create some standalone CPANEL.EXE file just via that one project. Rather, you would need to use a customized Windows OS build process to build the whole OS, which would then contain a CPANEL.EXE that would run within that built version of the OS.
Most of the AOSP apps work this way. Some have been forked to create standalone apps -- K-9 Mail came from the early version of the AOSP email app. I have no idea if anyone has done this with the stock AOSP Messaging app or not.
You could instead fork TextSecure[0] as it is no system application but looks very similar to the stock messaging application. The AOSP application needs to be installed on /system/app which requires root and might not be what your customer wants.
Please note that this application is copylefted (GPLv3) so you'd have to give your client access to the source code under the terms of the GPL if you fork.
[0] https://github.com/WhisperSystems/TextSecure

is it possible to create a complete Android app with SL4A?

I would like to create an App with python, but i need that it includes all it needs in order to operate correctly. I have saw this post about the ability to sell the app via and Market, but it didn't have a final answer there.
Currently the best solution i could find, is at this pdf chapter (from Pro SL4A Apress book), but still it seems that even if i create an .apk file, the user whom install that app would have to have the SL4A on his Android device.
Is there a way to incorporate the SL4A in the .apk file, or better yet, to incorporate just the needed stuff ?
As far as I'm aware, APKs created this way don't include the script interpreters that SL4A provides. According to the PDF you posted, it should request for SL4A and the relevant script interpreter to be installed when the APK is installed, however.
This question is now quite old, but for any other users who might come by here, it is now possible to embed the Python interpreter in an APK package. Look at this project for instructions and methods of doing so.
so what actually happens when compiling an APK via the method described in the book is a little bit different than what you have described. What actually happens is that upon installation of the APK file it will check to see if the user has Python installed, not SL4A. If the user does not have Python installed it will prompt for a download, similar to how certain applications prompt to install BusyBox in order to use certain commands. This means that the user doesn't need to have a scripting environment, or in fact even know what python is.
As for compiling 3rd party modules/libs into your APK, what happens is when you are compiling in Eclipse it will point to the folder on the computer containing python, and compile from there. That means that all you need to do in order to get extra modules or libraries into the APK are to make sure that they are included in the folder that Eclipse looks to when compiling the APK. By default I think that is your native Python folder, but I'm not 100% sure so somebody please correct me if I am wrong.
Hope this helps!

Categories

Resources