I have been searching for this answer for days and can't find a straightforward answer. I am working on an application written in C++ and that has been ported to Android. I am able to launch and run without too much hassle. My task is to figure out how much RAM our app is using dynamically so that we can handle memory issues dynamically-- which in my mind means that I need to have something in my C++ that can somehow be aware of system characteristics. What I have been able to do, is in my Java code, I can pull certain metrics that belong to my app via the getMemoryInfo call. Like in this post: Programmatically find Android system info
However, I would really like to be able to probe this from our C++ code so that we can handle everything in there...
Is this even possible?
If it is, are the calls unrealistically expensive?
If it is not, how is it possible to manage your memory through the native code rather than the Java code? i.e. If I see that I only have x amount of RAM available, I can dynamically change how much memory I want allocated to something in my C++ code to accommodate what the system has to offer.
Something along the lines of:
Ex. C++ Code:
if (android.os.thisApp.RAM left < 20 )
allocate 10M
else
allocate 20M
Related
I'm working on a drag and drop app builder. The concept is simple: users can build their apps visually, then the app's settings get turned into a configuration file which will be used by the app to decide how to construct itself (which views should be shown, how should the navigation look like, etc.)
My main concern is once the users download the apk (or ipa) file, they can decompile it, change things in the configuration file and re-compile/re-sign it to be published as a brand new app.
I was thinking about putting part of the logic on server side but that would introduce me the following problems:
If 1000 people built and published an app with my software, and each app sends only 10,000 daily requests to my server, that's already 10,000,000 requests per day, which would be pretty expensive.
If my server is down for any reason, I will have a lot of angry users coming at me.
Got any ideas?
There is no exact way of stopping decompilation/reverse engineering process of android app or apk !
But there Some chances to reduce the scope of code visiblity after decompilation/reverse engineering process !
Here are some habits I am sharing
1) Put important code on a Server : You may rely on remote procedure calls to a well protected server. This reduces the chance of your codes being stolen as the code will always remain on the server and nothing other than the results can be seen.
2) Debugger Detection Techniques : Insted of using the hard coated values or string use some formula or encryption methods which can help to hide the actual values
3) Write important parts of code in C/C++ :You can also write the important parts of your code in C/C++ and add them as a compiled library. While it can be disassembled into assembly code, reverse engineering a large library from assembly is extremely time-consuming. Java is easier to decompile in comparison to C/C++.
These are some key habits which are be taken care by good developer , You should also check out this answer as well !
Huh, I knew it wasn't possible to stop the decompilation/reverse engineering process on any android app. But, I thought maybe everything was possible! Like, perhaps something has changed since then, but no. Basically, I use the same steps as Nisarg Jani described. But, you have to pay some special attention to the C++ code. Any mistake will destroy everything that you have built to that moment. So, if you use a no-code desktop app builder, you should be aware of those "tips and tricks." Besides that, you should keep in mind that without the C++ code, you won't be able to do anything.
I have a simple application that contains two implementations which I want to compare(benchmark) with each other in terms of usage during a certain amount of time.
The testing method is equal for both implementations (they both execute exactly the same commands/events) the only difference is the way they process the command and events.
I wish to get a log per second of:
CPU load
Memory usage
Network traffic
The Android Monitor provides everything I need in a graph and logs per second the current CPU load, Memory usage and the TX/RX for network traffic, great!
However I wish to have this all in a text log instead of a live graph. Can someone tell me where I could find such a log? OR if there is no such thing, any suggestions to get similar data?
Doppie, I looked for a solution using out-of-box tools, but there is no good way to use the Android tools to export just the information you want to a text file without lots of work. Logcat is way too verbose and requires conversion, and Dalvik doesn't exactly provide you the every-second control over data collection. I would love to have a simple solution for this too. :/
[Disclaimer: Because I work with Perfecto, I know that the devices in their cloud lab can do this easily, so if you are trying to diagnose a specific problem, you could use their free public cloud and export the device vitals (shown below). This is not a pitch, but since it's free to play, it might help you in the short-term.]
hi first of all if you looking for memory logs. There is one option you can directly go and check that one.
Open Android Device Monitor then checks heap dumps.Check the uses of memory.
Another way to monitor Android Device Monitor then see the Allocation Tracker it gives you details in everyclass where you memory is used.
Expect these things you can directly check your Current logs.
Click Android Monitor and see logcat and second option Monitors.
Monitors gives you Four type of details :
1. Memory usages.
2. CPU how kuch usages of your phone.
3. Network
4. GPU.
Now after these all things. If you still have some problem then need to check your gradle.
What kind of libraries you used.
First of all remove unwanted libraries.
Secondly need to import only useful libraries. Like if you looking for map related things in your app then import only.
compile "com.google.android.gms:play-services-maps:9.4.0"
not this one.
compile 'com.google.android.gms:play-services:9.4.0'
Aware about replication of libraries.
Example : If you using some libraries and that libaray contain appcompt and you are also using same libaray in your app side.Then its better to use that libaray as module.
At last try to use proguard rules.
These are few ways to handle better memory management.
I have made one android app architecture here is link..
Thanks hope this will help you.
Ay up.
I'm currently in the process of making a game - it's a C++/SDL2/OpenGL combo which on PC works reasonably well. The long-term goal is to make this portable, though given that I lack most of the equipment to shove it onto every platform under the sun, the first "port", as it were, is likely to be for Android-powered phones and tablets.
SDL2 has an official (or "officially endorsed") port to Android, and after many weeks of haggling with Java and Eclipse and a mostly broken OpenGL ES 2.0 renderer, I've got stuff running on my lovely Nexus 7 tablet. It's not fast or pretty, but it's something to build on.
However, my game, as I would imagine many games like it, relies heavily on reading (and writing) data to and from XML files, be it saves, options, levels, you name it. But the Android NDK compresses all but a few file formats upon compilation - SDL2 has functionality to claw out images and audio from the Android-created /assets/ folder (where all my stuff is stored), but I use TinyXML2 for my XML handling, which can't cope.
There seems to be a small handful of possible solutions (it's a problem that turns up quite a bit - I'm well aware the "Similar Questions" box on my right is filled with similar woes as I type this), but each one seems to have either pretty big caveats or make pretty big assumptions about how the code is written. End results often being pointers to wacky variable types that won't fit neatly into tinyxml2, or I get stuck half way through because it turns out a piece of the puzzle isn't there. It's super frustrating.
Method a) seems to involve decompressing the apk at runtime and accessing the assets by brute force. It sounds like a really bad way of doing things and in some cases seems to assume the apk is placed in a specific location. Sounds pretty terrible to me, and complicated to achieve?
Method b) has the Java side effectively pass a pointer to the Android asset manager to the C++ side. This seems better, but examples I've seen of Java-to-C++ Android communication seem geared around very small "Hello World"-style projects where you're just passing across a string or a number. I also read this involved compiling Java headers and doing something novel with that- a process that would then fail because the Android asset manager isn't a standard data type or whatever.
c) SDL_RWops is meant to be geared up for Android and may be a preferable way of reading data from files. But it doesn't solve the subsequent brick walls as I try to convert this stuff into something tinyxml2 will understand.
Method d) seems to suggest you can get away with changing the extension of assets to that they're not compressed. So all my XML files become unofficial PNGs or whatever. That sounds terrible too, not least because I have 40+ XML files that would need to be managed. Supposedly there's a way to adjust what files are or aren't compressed, but some seem to think it's all or nothing, and I'm not sure how it's done regardless.
Understand that when you've been at at this for hours it's easy to let yourself be mislead. While I acknowledge the merit of figuring this stuff out for yourself, clues online are often incomplete, out of date, or are flat-out wrong.
So yes, a simple guide would be lovely. I've wasted many days exploring options and I'm sure it would be beneficial to the world to have a definitive answer.
As said, this works fine through the Windows PC build - reading and writing isn't a problem so I know it's not something stupid like dodgy files. For the Android port I'm using Eclipse and as said, the tablet I'm testing on is a Nexus 7. I have working knowledge of C++ and Java, but these fiddly bits drive me round the bend.
Thanks in advance
Well okay, I've taken a bit of a break and returned to this puzzle, and given that the situation hasn't really changed in terms of online tutorials or documentation or whatever, I've gone for the stupid option (option d) - I wrote a batch file to convert my XML files into JPEGs en masse, and now the program looks for JPEGs to read from and write to. How terrible.
On the plus side, tinyxml2 appears to be loading these fake JPEGs, but things crash as soon as it's given the command to look inside for specific elements, leading me to think it's probably not loading things properly (but at least it's no longer crashing on file load).
Debugging is painful and this whole strategy feels dirty and wrong. And there's nothing more disheartening than struggling with a question that presumably almost every Android game developer working in C++ has already answered in some form. Reading and writing files - why is this a challenge?
I want to find the total number of machine instructions of an Android Application. I have explored the Debug.InstructionCount class of Android SDK, but I believe it provides info of Dalvik VM instructions (not the machine level instructions which actually executes on the processor).
I need this info to estimate the time required for the execution of an Android application on a particular processor (using fixed frequency). I am aware of the fact that different type of instructions take variable cycles due to which the computational time cannot be estimated accurately, but I still want to do some experimentation. Thank you
My solution involves writing an instruction set simulator, running the app and counting the instructions. There are already open source avr simulators out there than you can just use/modify for this.
At the end of the day in order to do this you have to follow the instruction flow, so either you actually sim it and that automatically solves how many times the code really goes through a loop and such, or you write a disassembler (which is half of a simulator) and basically follow the code flow in execution order (actually much simpler than a full disassembler or simulator) but you have to deal with all the possible code paths and loops as you find the different paths and count the different paths. With minimal work you could come up with the shortest possible path and know the code could never be faster than that.
A coworker and I were talking (after a fashion) about an article I read (HTC permission security risk). Basically, the argument came down to whether or not it was possible to log every action that an application was doing. Then someone (an abstract theroetical person) would go through and see if the app was doing what it was supposed to do and not trying to be all malicious like.
I have been programming in Android for a year now, and as far as I know if -- if -- that was possible, you would have to hack Dalvik and output what each process was doing. Even if you were to do that, I think it would be completely indecipherable because of the sheer amount of stuff each process was doing.
Can I get some input one way or the other? Is it completely impractical to even attempt to log what a foriegn application is doing?
I have been programming in Android for a year now, and as far as I know if -- if -- that was possible, you would have to hack Dalvik and output what each process was doing.
Not so much "hack Dalvik" but "hack the android.* class library, and perhaps a few other things (e.g., java.net).
Even if you were to do that, I think it would be completely indecipherable because of the sheer amount of stuff each process was doing.
You might be able to do some fancy pattern matching or something on the output -- given that you have determined patterns of inappropriate actions. Of course, there is also the small matter of having to manually test the app (to generate the output).
Is it completely impractical to even attempt to log what a foriegn application is doing?
From an SDK app? I damn well hope so.
From a device running a modded firmware with the aforementioned changes? I'd say it is impractical unless you have a fairly decent-sized development team, at which point it is merely expensive.
This is both possible and practical if you are compiling your own ROM. Android is based on Linux and I know several projects like this for Linux, like Linux Trace Toolkit. I also know of research into visualizing the results and detecting malicious apps from the results as well.
Another thing functionality like this is often used for is performance and reliability monitoring. You can read about the DTRACE functionality in Solaris to learn more about how this sort of stuff is used in business rather than academia.