Does UCDetector work for android projects? - android

I've got an android project that I started from an old standard Java project, so because of the vast difference in target platform, I have a lot of dead code to cleanup.
I've seen UCDetector recommended for finding unused public methods in java projects in Eclipse. I installed it as directed, and it just doesn't show up on the menu, and I have no idea how to get it to work.
Has anyone got this combo to work, or have another recommendation? Or know how to get it to show up?
(I've tried Find Bugs which found some good stuff, but it doesn't find unused public code.)

Big warning!
It might partially work, but beware, cause it doesn't seem to know about XML-defined callback functions.
If you have installed a callback function on a widget, say a button in an XML Style Sheet, and it is not called in code, UCdetector will think it has 0 references, and suggest it deleted. This obviously is wrong, and will render your code uncompilable.
There might be other similar issues, related to Android specifics.
Viggo

Yes, UCDetector works for android projects. I just installed it and it works.
It's available in context menu of project in Package Explorer.

Related

INSTALL_FAILED_DEXOPT when using GreenDao

Background
I wanted to simplify the usage of DB in an Android app.
For this, I've compared some third party libraries that create a DAO layer.
I've come up with a nice library called "GreenDao" (presentation about it here) . The website shows that it's faster than other competitors (like ORMLite) and is optimized for Android.
The problem
For some reason, on some device (usually old devices, with GB) , I get the next console error when trying to install the app:
Installation error: INSTALL_FAILED_DEXOPT
Please check logcat output for more details.
Launch canceled!
I've searched for the reason of this error, but couldn't find out how to solve it. Many complain about this error, but I can't find out why it occurs, and what can be done.
The error is quite common and known, but it's never mentioned as the result of using this library, yet when I remove the usage of this library, everything works fine...
Also note that on newer devices (like nexus 4) it installs and works just fine, and that the sample itself also works fine no matter which device I test it on.
The question
Why does it occur?
Is it possible that the structure of the classes is just too much for old devices to load, since we use other libraries ?
Could it be that I've reached the limit of code that is supported by android apps?
The jar file itself takes just 87KB ...
How can I solve this?
Ok, I've found the problem and the solution:
It has nothing to do with GreenDao.
It's because the app uses too many jars, so maybe Android has a limitation of code.
The solution is to either delete un-needed jar files or delete a lot of code.

Running apps containing large amount of code

Background
It seems some old Android OSs (and maybe even the newest ones) have a limitation on the amount of code each app can hold.
As I've found, the limitation is on a buffer called "LinearAlloc" .
On 2.2 or 2.3 it's about 5-8 MB , and I think it's 16 or more on others.
The problem
If you have a too large code (and apps can reach this state), you won't be able to install the app at all on older devices, getting the next error (also reported here) :
Installation error: INSTALL_FAILED_DEXOPT
Please check logcat output for more details.
Launch canceled!
What I've found
One solution is to just remove as much code and libraries as possible, but on some huge projects such a thing is very hard to do.
I've found the next links talking about how Facebook solved this, by somehow increasing the limit:
http://www.slashgear.com/how-facebook-fixed-its-gingerbread-dalvik-problem-04272478/
http://arstechnica.com/business/2013/03/how-facebook-dug-deep-within-android-to-fix-its-mobile-app/
https://www.facebook.com/notes/facebook-engineering/under-the-hood-dalvik-patch-for-facebook-for-android/10151345597798920
Also, Google has posted how to solve it by loading code dynamically :
http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html
The question
How did Facebook do it?
Is it possible to overcome this in other ways too?
Is there any free library that increases/removes the limitation of this buffer?
What is the limitation on newer Android versions, if there is any?
How do other huge apps (and games) handle this issue? Do they put their code into C/C++?
Would loading the dex files dynamically solve this?
The limit is the total number of method references:
https://code.google.com/p/android/issues/detail?id=7147#c6
https://code.google.com/p/android/issues/detail?id=20814#c6
A middle ground between doing nothing and the multi-dex approach described in the FB/Google articles is to use a tool like ProGuard to remove references to unused code at the Java level. See:
http://proguard.sourceforge.net/
http://developer.android.com/tools/help/proguard.html
There is a new solution, made by Google:
https://plus.google.com/+IanLake/posts/JW9x4pcB1rj?utm_source=Android%20Weekly&utm_campaign=59f1f4bf4d-Android_Weekly_125&utm_medium=email&utm_term=0_4eb677ad19-59f1f4bf4d-337848877
http://developer.android.com/reference/android/support/multidex/MultiDexApplication.html
It seems all you have to do is any of the next things:
- extend from "MultiDexApplication" instead of from "Application"
- call MultiDex.install(context) in your application's attachBaseContext
But now I wonder:
Is that really it?
Does it have any issues ? Does it affect performance?
How does it work?
What should be done with ContentProvider, as it's getting called before Application gets initialized?
The post says "gives you MultiDex support on all API 4+ devices (well, until v21, where you get this natively)" . Does it mean that from v21 it will be the default behavior, or just that the class will be built in and you won't need to use the support library's class ?
Will this solution work on Eclipse too?

Android ActionBarCompat Not working from the start

OK, I have been wanting to try the new ActionBarCompat, however, I am not able to run my programs in the emulator.
I have been trying to implement the following: http://antonioleiva.com/actionbarcompat-how-to-use.
and have been stuck on basically the first part. However, working with the author of that content, I was able to get further as I was not adding the project under sdk\extras\android\support\v7\appcompat folder like stated. However, I still think that might be the reason I cannot do this...
More detail can be found here: http://antonioleiva.com/actionbarcompat-how-to-use/#comment-43
Basically, on my first attempt, I just created an Android project, and changed the source code as indicated. Code would not run on the emulator. So I went back to the original code, and that ran on the emulator.
Checked online, found out I might need to add the \extras\android\support\v7\appcompat folder as a library to the project I am building. So I added that and a new android project was created. There were build errors from the start, but I failed at trying to add it as a library to my project, and deleted it....thinking this was way overboard.
After back and forth chats with author of linked website, I found out I had to do that overboard thing.
So I tried the following link to the T: (I cannot post more than 2 links due to low repuation...I will add this link as a comment below)
However, Eclipse would not allow me to add the appcompat Existing Android Project...but it did allow me to add the appcompat Existing (General) Project. I think this may be some of the problems??
Right now, I cannot run the project at all. Eclipse is showing a red exclamation mark on the project folder, but all the code seems to be fine. So I don't know what to do now...I recreated this project several times over, and this one was the one where I knew what to do...and I am still getting problems
So...
I decided to move to Android Studio...updated the IDE, updated the SDK manager to include the new support library, and other things. Created a new project, added to the build.gradle file as shown in the link provided below in the comment. I ran the ant build, and then built the project...tried to import the right things to allow ActionBarActivity, but I could not get that far.
I can import
"android.support.v7.*"
"android.support.vy.R" // and all folders within
but nothing allows me to add ActionBarActivity, and I don't know why.
FYI, I guess I would prefer a solution to Ecplise, as it seems like I actually got somewhere with it.
The best example to use is from here, and I would follow it closely. I had similiar issues when I first came across this. Problem was I misunderstood what I needed to do
http://developer.android.com/tools/support-library/setup.html#libs-with-res

Mobclix ADs inside Unity3D

I have lost much time solving this problem, and looks like I'm back at the beginning.
I want to run the full screen ADs from the Mobclix inside my Unity3D game. I found many tutorials but I can't get any of them working.
As far as I know, there are 2 approaches:
1.) extending unity player
2.) make JAVA side method for showing the AD's and just call it from the unity(c#)
Most important for me is to make it work, but I would prefer 2. approach.
Can somebody suggest me something and maybe give some hints/examples what am I missing?
I tried both ways. I made an JAVA plugin but when I try to call a method nothing happens or I got an error from JNI something like: "can't find that method", my manifest is not configured correctly, or my app crashes.
If I'm making a plugin (not extending UnityPlayer) do I need to add something to the manifest to support my activity/make my class able to call inside unity? How would the manifest look like? Can it be done that way?
If I'm extending the UnityPlayer how would mthe anifest file looks like and how can I call my method for that will show ADs?
I tried to call java/android methods from the unity/c# and that worked, but when I try to call my own simple method from the plugin it won't work. Looks like I'm missing something in that part. (connecting the JAVA plugin and the unity3d)
I'm experienced in the C#, but my JAVA knowledge is really at the minimum. I'm sure this can work (there are people that are selling solutions) but looks like I'm not smart enough and keep missing something :)
I tried many things, I stopped counting and deleted most of them. Can somebody tell me the right way to do this? A working example would be really useful...
Thanks for taking the time to read all of this, I hope there will be some useful responses because I'm starting to get depressed :)
Unfortunately, it looks like the absolute easiest way is to purchase a plugin, made just for this. I found one here, which costs $50, and it specifically stated it supports fullscreen Mobclix ads.
There is a free one developed by the staff at Unity3D forums, however, it seems more complex, in that you must run it on the actual android device, and I am not sure if it supports full screen. You can find the discussion thread here.
Hope these links helped!
Edit: I found a much more affordable £6.00 Unity3D plugin, which you can get here. It did not explicitly state support for fullscreen, however.
Note: I found a tutorial from the very same website that offers the £6 plugin. This tutorial might be worth checking into, however it involves compiling your own Unity Android plugin. Because it is from the same website, it may be worth checking into. It is specifically a plugin to display Mobclix ads on a Unity3D for Android app.

Setting up Renderscript

I've decided to start learning Renderscript as a possible solution to my next project. However, I'm having trouble even getting Eclipse to run the thing. I'm importing the examples that come with the SDK 11. It seems to have trouble importing the headers. Eclipse doesn't recognize the directives like pragma or extern. Also, whenever I include a required file such as rs_core.h a message pops up stating llvm-rs-cc.exe has stopped working. I assume there's some sort of setup that I'm missing, but I can't find anywhere on the web that explains it.
"Replace /platforms/android-[11|12|13]/renderscript with the version located at /platforms/android-14/renderscript" see this question.

Categories

Resources