Is there a way to recover an apk app - android

My laptop crashed and i lost my android project ive been working on for the past 6 month. I still have the debug version on my phone. Is there a way i can get the code from that?

Your best bet would be to download the APK from the device using "adb shell pm path [package-name]" to see where the APK is installed, then "adb pull [path]" to download the file on your disk.
Then use a program such as dex2jar to get the class files, and another Java decompiler to get something as close to the source code.
Getting back the XML resources is a bit more tricky. All I can think of is running "aapt dump xmltree [your-app.apk] [path-of-xml]" to get a dump of what your XML resource looks like, but you'd still have to build XML from that manually.
Hopefully you didn't have native code (.so files), otherwise you're probably screwed.

Oh ok - sorry i misunderstood the question in the first place. For the installed apk there could be a solution in this question: Does Android keep the .apk files? if so where?

Related

Android - Emulator: I/O warning : failed to load external entity

I moved my Android Studio away from my C drive over to my F drive to save up on space but now I'm having trouble running my app to test it with Android Emulator.
event log image
Emulator: I/O warning : failed to load external entity "file:/C:/Users/Robin/.AndroidStudio3.1/config/options/updates.xml"
The location where this file is situated is actually in F:/Android/.AndroidStudio3.1/...
How do I tell the emulator to check at that location instead?
I've added an environment variable ANDROID_SDK_HOME with value F:\Android
I've set custom paths in idea.properties in AndroidStudio/bin
I've set the gradle path to F:/Android
Thanks in advance!
ATM, The only solution I know to fix this was to create a symbolic/hard link for the original file into the directory where android emulator looked it up. Well, that's how I fixed this issue. My guess was the search path for the emulator was hard coded into android emulator source. That's only my guess though.
So, in your case, just create a copy / symlink (recommended, as updates.xml often got modified by Android Studio on update) like this maybe (pardon me, as I'm not a windows user).
mklink C:/Users/Robin/.AndroidStudio3.1/config/options/updates.xml F:/Android/.AndroidStudio3.1/config/options/updates.xml
Well, I'll update my answer in case I get a better solution for this. BTW, I hope this can be any help for you :)
I found the right solution, in devices already created before the folder move, you have to change (in each) the path folder in the related .ini files, locate in the new .android/avd folder.
Example:
path=C:\Users\Name\.android\avd\EmulatorName.avd
to
path=D:\Android\.android\avd\EmulatorName.avd
Same issue was happening with me. Was facing the external entity error. Tried a lot to solve it even tried uninstalling and reinstalling but nothing works. Then i tried locating each and every file associated with android studio including android studio project and there were many more stuff, was easy to find as all were in user of my c drive. I deleted each and every file , all the projects and the changes i have made to my android studio were deleted. Then i restarted the app. Works fine for mešŸ‘
I had the same issue.
after clicked File ---> Sync with File System, it works

Is it possible to Install Android Package (.apk) on the emulator without access to sources?

I think the answer is No but Iā€™m not 100% sure as Iā€™m a newbie with Android SDK.
So, I downloaded adt-bundle-linux-x86-20140702 to my CentOS 6.5 machine. Following the documentation, I was able to create an AVD using ā€˜AVD Managerā€™ interface (using the eclipse binary).
Iā€™m able to view my AVD that I created by running emulator -avd <name>.
I have a .apk file which I didnā€™t build but downloaded from a website (I donā€™t have the source code). If I would like to load this .apk into my emulator to see how it works, is it something thatā€™s doable? If yes, may I know the steps please?
Many thanks in advance.
Update:
Following this link, I tried:
adb install /path/to/my.apk
which returns,
ā€œfailed to copy ā€˜/path/to/my.apkā€™ to ā€˜/data/local/tmp/my.apkā€™: No such file or directoryā€
I also tried copying /path/to/my.apk to the directory where adb is located. I created a /data/local/tmp directory as well with the same result. Perhaps, itā€™s looking for /data/local/tmp on the AVD (?). Not even sure if it is a compatible issue with the device/target/cpu configured on my AVD ..
Appreciate any help.

Installing a keylayout file (.kl) with android app (.apk)

i have tried and searched for days and was unable to come up with any solution for my problem:
I am trying to install a .kl file in /system/usr/keylayout to remap some keyboard keys for my app. I have the proper .kl file in the right format: Vender_XXXX_Product_XXXX.kl and it works if i copy it by using root explorer.
But I want it to be install (without root) by installing my app. Which means it has to be include in the .apk file and copied during installation!?
My approach so far was either with using a receiver and the QUERY_KEYBOARD_LAYOUTS intent.
For that a .kcm file is needed. That did not work with my phone (Galaxy S3). I do not know why but it does not show the PHYSICAL_KEYBOARD settings item in settings :(
Anyways i think/hope the better way is by NDK:
I tried using the ndk and was able to integrate some native c into my application but no "source" files like my .kl file.
I was hoping that a device.mk file would somehow be able to copy my .kl file to /system like so:
device.mk
PRODUCT_COPY_FILES +=
$(LOCAL_PATH)/Vendor_XXXX_Product_XXXX.kl:system/usr/keylayout/Vendor_XXXX_Product_XXXX.kl
Is that at all possible? To use the NDK to "install" a file to /system automatically while installing the actual apk?
And if so how do you do that? I am confused about the whole makefile thing and NDK. Never use that before and I am quite bad with c.
If any of you guys know how to do what I am asking ... please let me know. It would be greatly appreciated!
It's not impossible to install a .kcm file with an apk package. In fact that is just how layout apps do it. You are on the right track with the QUERY_KEYBOARD_LAYOUT.
I wanted to install a .kl file, just like you, but I couldn't find any good info on it. So instead I just used the map keyword in my .kcm file, it has the exact same effect.
Check out my source here, where I allow the user to add the se_sv_dvorak layout kcm without rooting the phone: https://github.com/innsmouthrain/se_sv_dvorak
But I want it to be install (without root) by installing my app.
That is not possible. Apps do not have write access to /system/usr/, unless they are running as root.
To use the NDK to "install" a file to /system automatically while installing the actual apk?
It is doubly impossible:
Your app does not get control when installing
Code written using the NDK does not gain any additional OS rights, and so such code cannot write to /system/usr/, except when running as root

Error when parsing a custom apk file

I started to look into Android programming today and created a very small app that is supposed to play MP3s. The tools I used where the Android SDK and eclipse. The code executed flawlessly in the Android emulator but after exporting it and attempting to install the apk on my Samsung Galaxy S2 I received a message telling me there was an error when parsing the file.
Here is my phone's configuration: Android v2.3.3, installation from unknown sources = allowed, USB-Debugging = enabled. The target system for my project has been set to Android v2.3.3 as well and the CPU architecture of the AVD has been set to ARM (armeabi).
I signed the apk using a custom keystone when exporting it, as I initially thought the problem might be a debug key which wouldn't work on real devices.
I attempted to install the app using both, the internal file explorer and a custom explorer (ES File Explorer) but it didn't work for.
Suggestions on how to make my phone execute my custom apps would be highly appreciated. :)
First, since it's complaining about the .apk file, try opening the .apk file by renaming the extension to .zip. If you can rename the file, and open it normally in Windows Explorer, then that should indicate the file itself isn't corrupt.
Secondly, I would try installing by connecting your device via usb and using the command adb -d install "path-to-your-apk-file.apk". If this doesn't work, hopefully adb will spit out something more descriptive, and you can update your question with the error.
I found the answer to the parsing error on custom apk files here. Removing the required API level tag android:minSdkVersion in AndroidManifest.xml solved the problem.

Repackage APK file to contain custom assets - what build tool to use?

Update: This is an old post, and references below to broken aapt versions will be out of date.
Based on previous feedback, I am storing custom text fields in the assets directory of my app.
I will write the app, using default user details in an asset file, and the client would like to rebuild the app for each user, including that user's details in the asset file.
(I am aware this is method has some serious shortcomings, but the client is still keen to do it in this way - see Embed login details in APK file, different for each user (or other options?))
This question relates to troubles I am having with rebuilding the APK file, once I have unzipped it, and updated the custom asset file. I am quite convinced I am missing something small, however, the documentation and posts I have found on these methods are not helpful enough for a newcomer.
aapt - Android sdk tool: Unfortunately the android docs on "Using aapt" on the android docs [link 2 below] are very limited. The console command -help shows a bit more info. When trying to use it to just add a file to the test.apk, it ends up deleting the original, and creating a new file test.apk.zip containing only the file I tried to add. I have not been able to find the correct command line combination to take an unzipped apk and repackage it - that would be my first prize.
apkbuilder - Android sdk tool: Firstly this tool is deprecated, which is a negative point for it. I also can't get it to work with what I have in that unzipped folder. I think I'm missing a pre-apkbuilder step because apkbuilder asks for a resource zip archive, and I have a resource folder.
ant - build tool: Other similar posts say to build with ant, rather than using the android tools. I am having trouble getting ant to work. One particular link to Getting Ant to Work with Android [link 3 below] looks promising but looks like it is for a different android sdk (my build.xml that is generated by android looks different to his). Unfortunately I know little about ant, and am having trouble becoming expert enough to solve my current issue.
Further to NickT's solution below - running the ant script gives me the error
taskdef class com.android.ant.SetupTask cannot be found using the classloader AntClassLoader[].
I have found some references online to this error, have confirmed that local.properties has an sdk.dir setting that is pointing to my android sdk install folder (sdk.dir=/Applications/android-sdk-mac_86).
?????: There might be some other option that I have not listed / discovered, which I would be interested in hearing about.
I realize that delving into the gears that are normally covered up by my ide can lead to diffuculties. But I know that a lot of the SO users can do many of these things, and I hope I get the interest of some of them. Thanks for any help.
(Eclipse 3.6 on Mac Snow Leopard 10.6 64 bit)
PS, I am not able to post more than 1 hyperlink yet, so I have included these addresses to show more info to my question.
(1): stackoverflow.com/questions/4783160/embed-login-details-in-apk-file-different-for-each-user-or-other-options
(2): developer.android.com/guide/developing/tools/aapt.html
(3): www.disgruntledrats.com/?p=27
To answer my own question with the method we finally chose, and "for the record":
I was unable to get Ant working correctly for me (my lack of understanding).
I ended up using the aapt tool. It works as per the Android sdk documentation and really is quite simple to use:
aapt add -v Test.apk "assets/readme.txt"
This will add a readme.txt file (we were storing it in a subfolder of the current running folder, called assets. If you want to store the new file somewhere else, aapt does offer a command line switch to specify that)
However, there are some caveats:
I couldn't get it to work on signed APK files.
some versions of aapt don't work properly! They don't recognise the subfolder...
To solve 1:
Export the APK from eclipse as an unsigned APK.
Use the keytool to generate a key (see Android dev docs).
Use aapt.
Sign the APK using jarsigner.
To solve 2:
I can't really help with this. Every version of the SDK (on Mac) I tried to download included an aapt tool that did not recognize the subfolders. A colleague downloaded a version that worked, but we could still not figure out which version it was that he downloaded, so we kept this "magic" copy and renamed it and will be using it until we find a new version that works.
The simplest solution would be to give the template source of the app to your client with a script that rebuild the app from scratch.
This way your client simply have to change the assets in the folder, double click a batch file and get the apk in a minute or so.
You don't have to know anything about ANT to compile and package without the IDE, just follow the steps here :
http://developer.android.com/guide/developing/other-ide.html
The ANT script is generated by the "android create" "android update" commands. You then just need to run "ant release" and off you go.
A bit late, probably, but this post appears in lots of searches, so I thought this may be of interest.
I just used a standard Zip tool to 'unsign' the APK by removing the META-INF folder, updated any asset files, and then resigned the APK using jarsigner. (If I could find a way to sign JARs without using jarsigner, so we wouldn't need the Java SDK installed everywhere, this would be really useful - ideas anyone?)
To expand on Yahel's answer, yes I think Ant is the way to go. It can be a bit intimidating, but it's urprising how well it works 'out of the box' without too much messing about. Customising it takes a bit of reading but I managed it, so I'll give you the benefit of my experience.
Firstly create a sample application as suggested. Let's suppose you want it to be created in c:\junk.
Then from your a command prompt in Android SDK\tools directory type:
android create project -t 5 -n AndSampleApp -p c:\junk\AndSampleApp -a AndSampleApp -k com.yourpackage.andsample.
( -t 5 gives you API level 7, type 'android list targets' to see other options)
Let's assume you've been building your projects in an Eclipse workspace (it's /dev/projects/EclipseHelios/AndroidWorkspace on my machine). Copy the sample app's build.xml and build.properties to the project folder in Eclipse
and edit the newly created build.xml and remove the line
<project name="AndSampleApp" default="help">
and replace it with just:
<project>
Now edit the the newly created build.properties which will be empty except for comments and add (customisng where necessary):
# The password will be asked during the build when you use the 'release' target.
# OH NO IT WON'T! IF YOU PUT THE KEYS & PWDS IN AS BELOW - It'S AUTOMATIC
# Customised (hard coded) section ---------------------
projectname=YourActualProjectName
# Line below is the parent folder of where the sources are
workspace.dir=/dev/projects/EclipseHelios/AndroidWorkspace
# Line below is where you want the binaries to go
outbasebase.dir=/dev/projects/AntBuilds
key.store=c:/users/you/your-release-key.keystore
key.alias=your_release_alias
key.store.password=YourSecretPassword
key.alias.password=YourSecretPassword
#------------------------------------------------------
ant.project.name=${projectname}
base.dir=${workspace.dir}/${projectname}
source.dir=${base.dir}/src
outbase.dir=${outbasebase.dir}/${projectname}
out.dir=${outbase.dir}/bin
layout.dir=${base.dir}/res/layout
If you then get a command line prompt in /dev/projects/EclipseHelios/AndroidWorkspace/YourActualProjectName
and type 'ant release', you should end up with a built and signed apk in /dev/projects/AntBuilds/YourActualProjectName
You should be able to customise the assets location by the adding an assets.dir entry in the build.properties

Categories

Resources