Around 2 days ago, i found out about the DexClassLoader Library by Android. As a rather mediocre programmer i have a few questions regarding this library/class/tool. The questions i have mainly focus on this Documentation:
It states, that it loads a external .jar or .apk file. Now lets assume i have my Project as follow:
com.me
-->src
---->main
---->fragment1
---->fragment2
-->layout
---->layout_main
---->layout_fragment1
---->layout_fragment2
How exactly would i now extract fragment1 with its corresponding layout into an .jar or .apk file, that my DexClassLoader can implement this file. And more importantly how do i transform these into such a file.
How do i implement all the functions i do have in my module (the exported Fragment)? I am guessing it is via an Interface, but i am neither sure, nor have found a good example online, as it kind of seems, as if it is a kind of underused feature.
Quiet similar to point 2, but how do i display this Fragment. If it is solved via an Interface, then i dont really have a way to call getFragmentManager().beginTransaction().add(R.id.smthng,Fragment1).commit();
Thanks for any sort of answer regarding any of these questions :) If i have more questions i will update this post. Cheers
Jacobus
Related
I have found Is there a way to decode a .ICO file to a resolution bigger than 16x16? from 2 years ago and the best suggestion was to use image4j. Unfortunately it does not work under android in particular (also), because the classes "IndexColorModel", "BufferedImage" and "WritableRaster" are not available.
While working around "BufferedImage" by replacing it with "Bitmap" may perhaps work and not using "WritableRaster", but instead setting individual (or a group of) pixels using setPixel may work as well, I cannot manage to replace "IndexColorModel", because I cannot wrap my head around it.
I am currently downloading a favicon from a website, which stores usually more than one image inside of it. The images are of different size. I read up on the structure of ICO files and analyzed image4j as much as I could. Yet I have troubles refactoring the various classes to not use AWT.
BitmapFactory is able to load ICO files; unfortunately it only loads the first image (this is my guess at least) and thus does not let me decide which image to load (let alone load them all and let me chose).
Does anyone know if anything changed from 2 years ago and/or would anyone be willing to help me refactor e.g. BMPDecoder from image4j? Or is there perhaps a totally different, easier approach to it?
I have created a library based on image4j that will allow reading ICO files into a List of Bitmap-objects. In contrast to image4j ico4a does not use any AWT-classes, but instead only makes use of Bitmap / Bitmap.createBitmap.
See https://github.com/divStar/ico4a .
While the library's performance might not be the best as it uses a Bitmap-object's setPixel method in a loop, it gets the work done and it's good enough for me.
In comparison to image4j my library (ico4a) only decodes/reads files. While saving ICO files could be done probably relatively easy, I have not done so since I do not need it myself.
If you have further questions or issues with the library, post them on gitHub and I will see if I can help.
I apologize in advance if this question or a similar question has already been resolved, but from my search on this site and others, I have failed to resolve my problem.
As the question title suggest, I wish to store the contents of a *dat file located on an external usb or sd card into a String variable within my main activity for further processing. I am new to java and android app development and only started tinkering a few days ago (I am an embedded design/robotics engineer and only have experience writing firmware in c/c++ for microcontrollers).
Could anyone suggest a way to do this, provide a code example, or provide a link to documentation or a library (or class) that I could use that would simplify things for me? I've been wrestling with this for several hours experimenting with various code snippets from the web. Please explain your response if you can, I am a newbie when it comes to java, app development, and android.
Also, do I need to edit the manifest to permit reading of files? If so, how?
Thanks in advance,
Caleb
I read the docs but I can't seem to figure out what the difference is. Is it something subtle that does not really matter? I want to create a cache of ten files. So when I went to use getExternalFilesDir, I noticed there is a getExternalCacheDir. So now I am confuse as to which one I should use (the name does not always tell the whole story). So can anyone put the difference in layman terms for me? thanks.
The ExternalFilesDir is not a cache, it will save your files, and they will remain there until the app is removed or the files manually whereas the cachedir will empty when needed
I'm a newbie to Android but would like to help you with the below link. The below article explores all possible ways / methods to use under different scenarios. It helped me in improving my understanding and hope the same with you and others as well
http://www.grokkingandroid.com/how-to-correctly-store-app-specific-files-in-android/
I want to transform/instrument Dex files. The goals of transformation include measuring code coverage. Note that the source files are not available. So instrumenting Dex is the only option.
I am wondering if there are any existing code base that I could look at as examples to write a tool to achieve my goal.
I know about the Smali project and a host of other projects that build on Smali. However, none of these projects are good examples for my purpose.
I am looking for code that automatically transforms smali code or the dexlib representation, from which smali is generated. The later option is preferred for my purpose because the overhead of generating smali can be avoided.
It's a lot of code, but dx's DexMerger is an example program that transforms dex files. It's made quite complicated by the fact that it needs to guess the size of the output in order make forward-references work.
You'd also need to create infrastructure to rewrite dalvik instructions. DexMerger's InstructionTransformer does a shallow rewrite: it adjusts offsets from one mapping to another. To measure code coverage your instruction rewriting would probably need to be much more sophisticated.
Another option that have become available recently is Dexpler. It is an extension of Soot, which is a framework for analysis and instrumentation of Java programs. Dexpler reads in .apk files and converts to Jimple intermediate format. Jimple code can then be arbitrarily instrumented, and eventually dumped into a new apk.
(For the record, I am answering my own question here)
Eventually I did not find any tool that fit my requirements. So I ended up building my own tool, called Ella, based on DexLib. Out of the box, it does a few things such as measuring code coverage, recording method traces, etc. But it can be easily extended to do other types of transformations.
In some cases smali itself does a small amount of instruction rewriting while re-assembling a dex file. Things like replacing a const-string with a const-string/jumbo, or a goto instruction with a "larger" one, if the target is out of range. This involves replacing instructions in the instruction list with potentially larger ones, and the corresponding fixing up of offsets.
CodeItem.fixInstructions is the method responsible for this.
Additionally, there is the asmdex library. I'm not all that familiar with it, but it sounds like it might be relevant to what you're wanting to do.
I know it's a bit late but just in case you're still interested or perhaps for some other readers. ASMDEX has been mentioned already. And I think that's your best bet for the moment for what you're trying to achieve.
As for adding new registers take a look at org.ow2.asmdex.util.RegisterShiftMethodAdapter class. It's not perfect! As a matter of fact as it is it's horrible changing existing 4bit instructions when adding a register would mean some register would end up being 0xF and won't fit in 4 bits.
But it should be a good start.
This has been talked about a few times, with varying states of success but most of the answers I can find are several years in the past.
Essentially, I have an application which has moved to a point where isn't being shared with customers. Customers want to extend the application but we don't want them to have access to the original code -- protecting IP on all that.
The layouts, images, etc... well, we don't care about those as much, only the java code. I could easily compile the java code into a jar and distribute it, but that's only half the answer. The java code still references a whole pile of internal resources.
The scenario I'm working with is jar file contains the following:
In Jar file
- MyActivity extends Activity
- onCreate() within MyActivity sets the contentView to an R-referenced layout from within the jar file.
In client application
- MyClientActivity extends MyActivity
When this is run, I get a ClassNotFoundException on MyClientActivity.
Things I've noticed:
- If I attach the jar code as a library, instead of a jar file, it works.
- If I remove the R reference within onCreate() in MyActivity and remake my jar file, it works.
So, obviously, as pointed earlier, the R references are dead/not accessible. The thing is, this apparently can work, no? If you create an Android application and look at the auto-included APIs, the android.jar file has an R file, with internal layouts/strings/etc... which are being references from within its code.
As others have said before, this seems like a very basic and obvious usage pattern. The fact that it seemingly doesn't work is mind boggling enough to lead one to believe that it does in fact work, it's just not done in an obvious way.
Has anyone ever actually gotten it to work?
Thanks a lot,
-Cord Awtry