I recently discovered a fatal error in my android app running on Android version 10 from this line:
((Button)alert.findViewById(android.R.id.button1)).setAllCaps(true);
I have set android:minSdkVersion="9" in AndroidManifest.xml.
The root cause was android.widget.Button inherits from android.widget.TextView and the setAllCaps method was implemented in API level 14.
Reference: https://developer.android.com/reference/android/widget/TextView.html#setAllCaps(boolean)
So my question is why can't I get lint to discover this class of error?
I would presume that lint --check NewApi . would find this kind of issue.
Is it because the dialog which has this button is dynamically created just before this code?
Is there anything I can do to help lint prevent this class of error? In a perfect world I would like warnings to be thrown for any methods called from SDK versions higher than minSdk.
Related
My project specifies support-v4-26.1.0 as one of its dependencies, which in turn uses
android.library.reference.1=../support-compat-26.1.0
android.library.reference.2=../support-media-compat-26.1.0
android.library.reference.3=../support-core-ui-26.1.0
android.library.reference.4=../support-core-utils-26.1.0
android.library.reference.5=../support-fragment-26.1.0
On Android sdk 10, this crash occurs:
Could not find class 'android.support.v4.app.FragmentManagerImpl', referenced from method android.support.v4.app.FragmentHostCallback.<init>
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: android.support.v4.app.FragmentManagerImpl
at android.support.v4.app.FragmentHostCallback.<init>(FragmentHostCallback.java:46)
at android.support.v4.app.FragmentHostCallback.<init>(FragmentHostCallback.java:63)
at android.support.v4.app.FragmentActivity$HostCallbacks.<init>(FragmentActivity.java:871)
at android.support.v4.app.FragmentActivity.<init>(FragmentActivity.java:100)
How can this be fixed?
Edit: I decompiled my apk and see that FragmentManagerImpl exists in android.support.v4.app package, so it's not a ProGuard issue.
FragmentManagerImpl implements Factory2, which requires API 11. This should be the reason for the NoClassDefFoundError exception: at moment I don't know how to fix this. I tried extending that class but it isn't public.
Anyway I'll continue looking for a solution even if API 10 isn't supported at the moment because I want to keep my app's compatibility high.
English mistakes? I'm an Italian teenager, sorry :-)
(I am unsure if everyone else faces this problem, but I do)
I am accessing setHour(int) and getHour() (and the minute's getter and setter) of android.widget.TimePicker - IntelliJ doesn't complain of their inexistence, but when i run the program from my phone (or emulator) it crashes and i see an error log of java.lang.NoSuchMethodError android.widget.TimePicker.getHour. (Other minute/hour getter/setter include).
I tried accessing the definition for the TimePicker class (Ctrl+B) and I realised every method contained a line: throw RuntimeException("Stub");
So what's this; How can I move on?
IntelliJ doesn't complain of their inexistence
That is because you are compiling against API Level 23.
but when i run the program from my phone (or emulator) it crashes and i see an error log of java.lang.NoSuchMethodError android.widget.TimePicker.getHour
That is because getHour() was added in API Level 23, and your device or emulator is running Android 5.2 or below.
I don't use IntelliJ, but it should be complaining about your build. In Eclipse and Android Studio, you would get an error from Lint indicating that you are calling a method (getHour()) that exists in your compileSdkVersion (23) but does not exist in your minSdkVersion (whatever you have that set to, as the oldest API level that you are willing to support).
I tried accessing the definition for the TimePicker class (Ctrl+B) and I realised every method contained a line: throw RuntimeException("Stub")
That is because it is decompiling the android.jar that is in your compile-time classpath, which consists purely of stub implementations to satisfy the javac compiler. At runtime, your process' VM will have a version of that JAR that has actual implementations.
How can I move on?
Probably stop calling getHour(), unless you can get away with doing so only on Android 6.0+ devices.
Following an unsuccessful Lint run, I attempted to fix an error by adding the #TargetApi(Build.VERSION_CODES.HONEYCOMB) attribute, but the next time Lint is run, the following error still shows for the getScaleX() function:
Can anyone shed some light on this?
The call to getScaleX() requires API level 11 (Honeycomb), as mentioned in the message window. The message also indicates that the minimum API level is 9 (as per the minSdkVersion setting).
The Lint tool is warning you that you are using a method supported only in newer SDK versions (11+), but have set to allow the application to run on devices that don't support this method (SDK versions 9 and 10).
See a more detailed description of what the NewApi Lint check does here: (search for NewApi) http://tools.android.com/tips/lint-checks
Suppress such warnings with caution, I'd suggest protecting the code with something like this:
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
...getScaleX()...
}
I am trying to make use of the SlidingMenu Library for Android but I get these errors:
Could not find com.slidingmenu.lib.SlidingMenuActivity.apk
and another error:
E/AndroidRuntime(24767): java.lang.NoClassDefFoundError: com.slidingmenu.lib.SlidingMenu
I have properly added the com.slidingmenu.lib.SlidingMenuActivity to the Java Build section.
What I found is that some time between June 2012 and now (August 2013) the package name changed. Performing a global search-and-replace of com.slidingmenu.lib to com.jeremyfeinstein.slidingmenu.lib fixed the problem.
Troubleshoot Android 'Could not find somelibrary.apk'
Could not find Library.apk!
Troubleshoot Android 'java.lang.NoClassDefFoundError com.somelibrary.mylibrary'
Troubleshoot NoClassDefFoundError in Java
In my application I use RoboGuice and the configuration for RoboGuice requires to add an Application-class and specify it in the AndroidManifest.xml file in the application-tag using the 'android:name' attribute.
So this is how my applicaiton-tag in the manifest looks like:
<application android:label="Worktime" android:icon="#drawable/logo" android:name=".guice.Application">
This always works and still does when I compile inside my IDE (IntelliJ) and deploy it to my device.
However when I want to run my tests using Ant (and only via Ant, this also still works in the IDE) I have this error on the console:
[exec] android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests:INSTRUMENTATION_RESULT: shortMsg=Unable to instantiate application eu.vranckaert.worktime.guice.Application: java.lang.ClassNotFoundException: eu.vranckaert.worktime.guice.Application in loader dalvik.system.PathClassLoader#44e88928
[exec] INSTRUMENTATION_RESULT: longMsg=java.lang.RuntimeException: Unable to instantiate application eu.vranckaert.worktime.guice.Application: java.lang.ClassNotFoundException: eu.vranckaert.worktime.guice.Application in loader dalvik.system.PathClassLoader#44e88928
This has worked before but started failing since I upgraded my 'Android SDK Tools' to revision 17 and the 'Android SDK Platform-tools' to revision 11.
Anyone who had this issue also or who knows how to fix it?
I think that the error saying
java.lang.ClassNotFoundException:
is occur only when you have create new class Activity and not declare(register) that in manifest file
please check if you have any new activity and not declare(register) that activity in manifest file
Thanks.
we might have encountered the same error - In my case the solution was to separate the Ant targets to two calls (i.e. "ant myParameters myTarget1 myTarget2", and "ant myParameters debug delivery"). Hope this works for you, anyhow - Google need to add better support for their undocumented/faulty changes (and stackoverflow isn't the best place for questions that are not originated in stupidity, as the lifetime of a complex question isn't too long here).