Android: java.land.NoSuchFieldError after update to SDK 23 - android

I updated to SDK 23 and updated the gradle.build to API 23, support library to 23.0.0, etc and am now getting the following error when trying to run the app (compiles just fine).
java.lang.NoSuchFieldError: No instance field mFragments of type Landroid/support/v4/app/FragmentManagerImpl; in class Landroid/support/v4/app/Watson; or its superclasses (declaration of 'android.support.v4.app.Watson' appears in /data/app/com.my.app-1/base.apk)
at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:50)
at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:560)
at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:64)
at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:164)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:548)
at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:917)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:258)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
I reverted back to API 22 on everything and still get the error.

I did the some thing as you did ,
but I found gradle can solve dependencies,
in External Libraries i cannot find support-v4-23.0.0,support-v7-23.0.0 and other lib which the version is 23.0.0.
then I reverted back to compile 'com.android.support:support-v4:22.2.0',
the problem solver #mraviator

Thank you #zmarties for the answer , I want to add the details and links
Remove 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar' from gradle
Download actionbarsherlock module from this link!
Verify that you have 'com.android.support:support-v4:20.0.0' or 23
Open the actionbarsherlock module src change FloatMath to Math in AnimatorProxy.java
Open the actionbarsherlock module src create variable fragments in class level scope as FragmentManagerImpl fragments = (FragmentManagerImpl) this.getSupportFragmentManager(); in Watson.java
Replace all mFragments occurrence with fragments variable
Thank you for the above answers .

Using google play services version 8.1.0 instead of 8.4.0 solved on my side

I found that I could build ActionBarSherlock using SDK 23 if I made the following two sets of changes:
in AnimatorProxy.java, replace FloatMath calls with their corresponding Math calls
in Watson.java, replace the use of the mFragments field with a local variable fragments initialized via getActiveFragments(null), and then change the mFragment references to use the local variable

Did you change the theme view in the main layout from the design tab?
Try changing it again to a Sherlock theme view at the design tab.

i had the same problem when import project eclipse to Android Studio
This is best solution for me
I found that I could build ActionBarSherlock using SDK 23 if I made the following two sets of changes:
in AnimatorProxy.java, replace FloatMath calls with their corresponding Math calls - i change FloatMath - to Math
in Waston Class i had the error - mFragments.isadded
So,
i replace the follow code instead of checking
mFragments.isadded != null
to
mFragments.getActiveFragments(mCreatedMenus)
everywher when it required
i had solve these issues.

Related

Databinding NoSuchMethodError with buildtools 3.4.0

When using the latest DataBinding
classpath 'com.android.tools.build:gradle:3.4.0-alpha10'
A NoSuchMethodError crashes the app upon Activity load. Using:
classpath 'com.android.tools.build:gradle:3.2.1'
causes the databinding to work successfully.
Here's the crash:
java.lang.NoSuchMethodError: No direct method <init>
(Landroidx/databinding/DataBindingComponent;Landroid/view/View;I)V in
class Landroidx/databinding/ViewDataBinding; or its super classes
(declaration of 'androidx.databinding.ViewDataBinding'
Is there any way around this if we want to use the latest build tools?
One of your libraries relies on data binding and is distributed with generated data-binding classes built with build tools 3.3 (or earlier). The issue is caused by the breaking change introduced in the latest beta/rc version of the data binding lib. In version 3.4 the signature of androidx.databinding.ViewDataBinding constructor has been changed from:
protected ViewDataBinding(DataBindingComponent bindingComponent, View root, int localFieldCount)
to:
protected ViewDataBinding(Object bindingComponent, View root, int localFieldCount)
Which makes any generated data binding class binary incompatible with 3.4 databinding lib, resulting in the following exception upon startup:
java.lang.NoSuchMethodError: No direct method <init>(Landroidx/databinding/DataBindingComponent;Landroid/view/View;I)V in class Landroidx/databinding/ViewDataBinding; or its super classes (declaration of 'androidx.databinding.ViewDataBinding' appears in /data/app/com.example.idolon-LqF2y8dUMxZoK3PVRlzbzg==/base.apk)
at com.example.lib.databinding.ActivityLibBinding.<init>(ActivityLibBinding.java:20)
at com.example.lib.databinding.ActivityLibBindingImpl.<init>(ActivityLibBindingImpl.java:30)
at com.example.lib.databinding.ActivityLibBindingImpl.<init>(ActivityLibBindingImpl.java:27)
at com.example.lib.DataBinderMapperImpl.getDataBinder(DataBinderMapperImpl.java:316)
at androidx.databinding.MergedDataBinderMapper.getDataBinder(MergedDataBinderMapper.java:74)
at androidx.databinding.DataBindingUtil.bind(DataBindingUtil.java:199)
at androidx.databinding.DataBindingUtil.bindToAddedViews(DataBindingUtil.java:327)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:306)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
As a workaround you can rebuild libraries that contains data binding classes using the latest build tools.
The corresponding bug on Androig Bug tracker is: https://issuetracker.google.com/issues/122936785
UPDATE
The issue has been fixed and the fix is available in 3.5 beta 1 (it will also be available in the upcoming 3.4.1)

Gradle sync error using Navigation Component in base module

Using Navigation component alpha09 and have added apply plugin: "androidx.navigation.safeargs" to top of base module build.gradle but getting following error when doing gradle sync. I'm using Android Studio 3.4 Canary 9 (but also had same problem using 3.3 RC3)
It looks like a related fix was included in alpha09 - https://issuetracker.google.com/issues/119662045
Caused by: kotlin.TypeCastException: null cannot be cast to non-null type org.gradle.api.resources.TextResource
at androidx.navigation.safeargs.gradle.SafeArgsPlugin.setApplicationId(SafeArgsPlugin.kt:87)
at androidx.navigation.safeargs.gradle.SafeArgsPlugin.access$setApplicationId(SafeArgsPlugin.kt:39)
at androidx.navigation.safeargs.gradle.SafeArgsPlugin$apply$1$task$1.execute(SafeArgsPlugin.kt:63)
at androidx.navigation.safeargs.gradle.SafeArgsPlugin$apply$1$task$1.execute(SafeArgsPlugin.kt:39)
at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:360)
at androidx.navigation.safeargs.gradle.SafeArgsPlugin$apply$1.invoke(SafeArgsPlugin.kt:59)
at androidx.navigation.safeargs.gradle.SafeArgsPlugin$apply$1.invoke(SafeArgsPlugin.kt:39)
at androidx.navigation.safeargs.gradle.SafeArgsPluginKt$sam$org_gradle_api_Action$0.execute(SafeArgsPlugin.kt)
at org.gradle.internal.ImmutableActionSet$SingletonSet.execute(ImmutableActionSet.java:225)
at org.gradle.api.internal.DefaultDomainObjectCollection.doAdd(DefaultDomainObjectCollection.java:247)
at org.gradle.api.internal.DefaultDomainObjectCollection.add(DefaultDomainObjectCollection.java:236)
at com.android.build.gradle.LibraryExtension.addVariant(LibraryExtension.java:93)
at com.android.build.gradle.FeatureExtension.addVariant(FeatureExtension.java:121)
at com.android.build.gradle.internal.ApiObjectFactory.create(ApiObjectFactory.java:134)
Just updated to alpha11 and not seeing this issue any more. (https://developer.android.com/jetpack/androidx/releases/navigation#1.0.0-alpha11)
UPDATE
From comments below it looks like alpha11 didn't resolve issue for some people but beta1 did

Cryptic FCM 10.2.0 Failure - FirebaseInitProvider, NoSuchMethodError

I'm trying to add Firebase Cloud Messaging to my app with no success, as I get the following exception:
1 27336-27336/com.company.here E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.company.here, PID: 27336
java.lang.NoSuchMethodError: No static method zzb(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/google/android/gms/common/internal/zzaa; or its super classes (declaration of 'com.google.android.gms.common.internal.zzaa' appears in /data/app/com.company.here.debug-1/base.apk)
at com.google.firebase.provider.FirebaseInitProvider.zza(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5883)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5475)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5414)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1546)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6154)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Here's what I've checked so far:
google-services is set to 3.0.0 in the project gradle file
I only have one dependency related to firebase, which is 10.2.0
I have jack enabled so I can use lambdas
I have ReactiveAndroid and Retrofit incorporated into the project, perhaps they're interacting badly? That said I didn't see anything suspicious when running ./gradlew app:dependencies
Tried multiDexEnabled = true, didn't make a difference
Had a custom applicationIdSuffix for debug builds, attempted to remove it but it also didn't make a difference
Positioning of apply plug: 'com.google.gms.google-services doesn't seem to matter, currently at end of gradle file
What could be causing this? As best as I can tell, FirebaseInitProvider is calling an internal static method from attachInfo, which in turn attempts to call out to a static method on an SDK-private class that doesn't seem to exist.
So this was weird:
Nothing about my setup changed from last night except I ran the clean project command, added the firebase-core dependency and then built again, and everything started to work.
I had assumed that firebase-messaging pulled all of its dependencies in by itself, but that goes against the setup guide, and the crash makes sense if the internal class FirebaseInitProvider is attempting to access is in the firebase-core dependency.
You probably have a mismatch of one of your play-services dependencies and Firebase in your app level build.gradle.
Having google services at 3.0.0 in your project level build.gradle is fine (com.google.gms:google-services:3.0.0).
For example, if you have dependency com.google.android.gms:play-services-maps:10.2.0 and com.google.firebase:firebase-invites:10.2.0 they must both be the same version 10.2.0.

error: cannot find symbol method getColor(Context,int) after adding Sugar ORM to project

I would like to use SugarOrm in my app.
If I add the followings:
compile 'com.github.satyan:sugar:1.4'
to the gradle file
and
android:name="com.orm.SugarApp"
to my mainfest's application name
I get the following error on build:
Error:(75, 55) error: cannot find symbol method getColor(Context,int)
at this line:
holder.bg.setBackgroundColor(ContextCompat.getColor(ctx, R.color.primary_move));
If I checkout to a previous version without these 2 lines, my application builds and runds without error.
Any suggestions?
From the Android Documentation:
Helper for accessing features in Context introduced after API level 4
in a backwards compatible fashion.
Do you really need that backward compatibility? Try accesing getColor from the context. You can also still useContext.getColor() while you resolve the main issue however
I have updated to compile 'com.github.satyan:sugar:1.6' and error is gone.

How to use EasyMock in android

I use easymock-3.2.jar in my android test project.
I find it in its Home:
2013-07-11: EasyMock 3.2 is available. Add #Mock annotations and Android support.
However , I got exception when I use it.
java.lang.NoClassDefFoundError: org.easymock.EasyMock
I googled a lot , and add
dexmaker-1.0.jar
objenesis-1.2.jar
cglib-nodep-2.2.2.jar or cglib-2.2.jar
But the exception still be there.Who can help me?
Thanks a lot.
Put the library
easymock-3.2.jar
dexmaker-1.0.jar
dexmaker-mockito-1.0.jar
in tests/libs. And it will work.
Be careful , it's in tests/libs , not in tests/lib.
It will throw
java.lang.NoClassDefFoundError: org.easymock.EasyMock
if you position them in tests/lib.
The first step is to get EasyMock. You can get the latest version from Easymock’s download page. Choose the latest version and you will get a zip file. You only need easymock-3.2.jar (3.2 will change depending on the version you choose). You will also need dexmaker for Easymock to work on Android. You can get the jar from Dexmaker’s website. Once you have both jar files put them in /tests/libs. Now you have EasyMock available in your tests.
for more detail follow below link
http://ncona.com/2013/11/writing-unit-test-for-android-with-easymock/

Categories

Resources