Error inflating class android.support.v7.widget.RecyclerView - android

I'm trying to use RecyclerView in my existing project, builds without errors but getting no class found error for the RecyclerView while inflating. Cannot see what I'm doing wrong. Thanks for helping!
//activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
//MainActivity.onCreate
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
ItemData itemsData[] = { new ItemData("Help",R.drawable.visa),
new ItemData("Delete",R.drawable.sample),
new ItemData("Cloud",R.drawable.sample),
new ItemData("Favorite",R.drawable.sample),
new ItemData("Like",R.drawable.sample),
new ItemData("Rating",R.drawable.sample)};
// 2. set layoutManger
recyclerView.setLayoutManager(new LinearLayoutManager(this));
// 3. create an adapter
MyAdapter mAdapter = new MyAdapter(itemsData);
// 4. set adapter
recyclerView.setAdapter(mAdapter);
// 5. set item animator to DefaultAnimator
//recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setHasFixedSize(true);
}
//build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '19.1.0'
defaultConfig {
applicationId "com.domain.project"
minSdkVersion 19
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:+'
compile 'com.android.support:support-v13:+'
compile project(':facebook-3.15')
compile project(':parse-1.5.1')
compile project(':viewpagerindicator-2.4.1')
compile 'com.github.manuelpeinado.fadingactionbar:fadingactionbar:3.1.2'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.google.android.gms:play-services:+'
}
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
//LOGCAT
08-24 17:49:27.626 27544-27544/com.domain.project E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.domain.project, PID: 27544
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.domain.project/com.domain.project.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5139)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
at android.app.Activity.setContentView(Activity.java:1929)
at com.domain.project.MainActivity.onCreate(MainActivity.java:35)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5139)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
            at android.app.Activity.setContentView(Activity.java:1929)
            at com.domain.project.MainActivity.onCreate(MainActivity.java:35)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5139)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: android.support.v4.util.Pools$SimplePool
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:121)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:213)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
            at android.app.Activity.setContentView(Activity.java:1929)
            at com.domain.project.MainActivity.onCreate(MainActivity.java:35)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5139)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at dalvik.system.NativeStart.main(Native Method)

Or... in my case, I was including the androidx version of RecyclerView in my dependencies (build.gradle) but using the other in my XML... Doh.
Replaced
android.support.v7.widget.RecyclerView
with
androidx.recyclerview.widget.RecyclerView
and it worked! :)

In the xml declaration of the RecyclerView:
Replace
<android.support.v7.widget.RecyclerView
with
<androidx.recyclerview.widget.RecyclerView
Hope this works ^_^

Please check your support libs are updated to latest..
com.android.support:support-v4: and com.android.support:recyclerview-v7

for the new API Version, on the build.gradle - project dependencies add :
implementation 'androidx.recyclerview:recyclerview:1.0.0'
and in the layout, you should replace :
android.support.v7.widget.RecyclerView
with
androidx.recyclerview.widget.RecyclerView

In your layout file:
Use:
androidx.recyclerview.widget.RecyclerView
Instead:
android.support.v7.widget.RecyclerView
It will work for you.
If you do not want to use Androidx then in your gradle.properties file and do this:
android.useAndroidX=false
android.enableJetifier=false

My problem was that the library was compiled using JDK1.6 instead of 1.7.
Found the solution here link

Add Dependencies in gradle file.
dependencies{
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
}

Just add following into your proguard-rules.pro,
-keep public class android.support.v7.widget.** { *; }

Make sure you have added proper dependencies for recyclerView.
Then check whether you have dependecy for cardView.
If yes, then
remove card view dependency
sync project
then again add card view dependency
clean project
rebuild project
It worked for me

I figured it out. Removing the following configuration in build.gradle makes the recyclerview work. This leads me to another question: android studio: gradle dependency error
--
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}

After trying everything on internet i solved recyclerview inflating error by observing small mistake.
First,
Did you check your android-support-v7-recyclerview.jar library present in libs folder? if it is then check if your manifest file that has target sdk version to 21
<uses-sdk
android:minSdkVersion="11" //or whatever you need
android:targetSdkVersion="21" />
may be this can help for someone in future and not wasting days behind it as i did.

Check out my answer here Error inflating class RecyclerView.
In short, you need to import recyclerview and appcompat dependencies and sync before you are trying to add RecyclerView to your XML.

--- Quoted from Android website.
Dependencies
To use these features in versions of Android earlier than 5.0 (API level 21), include the Android v7 Support Library in your project as a Gradle dependency:
dependencies {
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
}

For make it work under Eclipse in my case I added RecyclerView as Library in the workspace. And then added to my project under ANDROID LIBRARY. Finally. Three hours lost.

I had a similar same error message, and tried many of the suggested steps from the answers on this site.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abc.def/com.abc.def.MainActivity}: android.view.InflateException: Binary XML file line #8:
Finally realized that for some reasons the tag in my layout was:
android.support.v7.internal.widget.RecyclerView
instead of
android.support.v7.widget.RecyclerView.
I am not sure how 'internal' crept in between v7 and widget, but once I removed that, the error went away. Not saying other people will make the same mistake, but just to let people know that a typo somewhere in your layout xml could be the cause of this error message.

Check your layout.xml file...Cant stop my laughing...
I made a stupid mistake...
I put
<android.support.v7.wodget.RecyclerView
instead of
<android.support.v7.widget.RecyclerView
look at the small 'o', it wasted me 30 mins or more to check other files...
[looking forward my answer can save your time]

Add below line in Gradle file:
dependencies {
//recyclerview
implementation 'androidx.recyclerview:recyclerview:1.0.0'
}
Add below code in your activity layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Your Android studio auto imports the androidx recyclerview.
AndroidX is a major improvement to the original Android Support Library. Like the Support Library, AndroidX ships separately from the Android OS and provides backwards-compatibility across Android releases.
Here is the reference AndroidX:
https://developer.android.com/jetpack/androidx

I too got same exception.
simple solution is add layout_behaviour to recycler view:
app:layout_behavior="#string/appbar_scrolling_view_behavior"

Related

Google Play Services and NoClassDefFoundError

I had an app working alright until today. To do some integration with a wearable module (I use Android Studio), I had to update Google Play Services from 6.1.0 to 7.3.0 (the latest). I also use an external library, which I know it works fine and there is no problem with it.
The thing is when I update my gradle file with the new Google Play Services version, I get the NoClassDefFoundError at runtime (complaining on my external library). I've tried everything, but nothing works (made sure the .jar is ok, that is actually exported, cleaned 1000 times, rebuild, delete build folder, etc). If I set the Google Play Services to 6.1.11 back, the app run as it used to be.
This is driving me crazy...
My build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:7.3.0'
compile files('libs/mylibrary.jar')
}
The error log:
05-06 15:23:56.544 31574-31574/com.rippll.okchat E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.rippll.okchat, PID: 31574
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/rippll/geowave/Geowave;
at com.rippll.okchat.MainActivity.onCreate(MainActivity.java:92)
at android.app.Activity.performCreate(Activity.java:5953)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
at android.app.ActivityThread.access$800(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
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:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.rippll.geowave.Geowave" on path: DexPathList[[zip file "/data/app/com.rippll.okchat-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at com.rippll.okchat.MainActivity.onCreate(MainActivity.java:92)
            at android.app.Activity.performCreate(Activity.java:5953)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
            at android.app.ActivityThread.access$800(ActivityThread.java:148)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5312)
            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:901)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Suppressed: java.lang.NoClassDefFoundError: com.rippll.geowave.Geowave
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:321)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 16 more
Suppressed: java.lang.ClassNotFoundException: com.rippll.geowave.Geowave
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Google Wear doesn't support Google Play Services v7.x yet.
So, you need to use Google Play Services v6.x in your Wearable project, for example in your build.gradle file of wear project:
dependencies {
compile 'com.google.android.gms:play-services:6.5.87'
}
But in your mobile (handheld) project you can use latest v7.x library version, if you're really need it, like:
dependencies {
wearApp project(':yourWearProjectName')
compile 'com.android.support:appcompat-v7:22.0.0+'
}
There is a limit of ~65000 methods for your .apk. Google Play services grow in size with each release and when you include them in your project you may very well jump over that method count limit. The solution is to use only the modules you need.
Please read carefully https://developer.android.com/google/play-services/setup.html

How does one inflate XWalkView in an XML layout (or programmatic)?

I'm having a serious problem with a runtime exception when inflating an XML layout that includes the XWalkView...
Stack trace :
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:233)
at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:237)
at org.xwalk.core.ReflectionHelper.init(ReflectionHelper.java:132)
at org.xwalk.core.ReflectionHelper.loadClass(ReflectionHelper.java:199)
at org.xwalk.core.ReflectionHelper$ConstructorHelper.loadConstructor(ReflectionHelper.java:37)
at org.xwalk.core.ReflectionHelper.createInstance(ReflectionHelper.java:246)
at org.xwalk.core.XWalkView.<init>(XWalkView.java:169)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.bean.project.XWalkUIActivity.onCreate(XWalkUIActivity.java:51)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            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)
Caused by: java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
            at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:237)
            at org.xwalk.core.ReflectionHelper.init(ReflectionHelper.java:132)
XML :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/com_bean_project_content"
android:theme="#style/com_bean_project_black" >
<!-- bottom controls -->
<RelativeLayout
android:id="#+id/com_bean_project_bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<!-- some buttons, nothing to worry about -->
</RelativeLayout>
<!-- fills most of the parent view -->
<org.xwalk.core.XWalkView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/com_bean_project_webview"
android:layout_alignParentTop="true"
android:layout_above="#id/com_bean_project_bottom_layout"/>
</RelativeLayout>
Things I have done :
1) in Android Studio, I am using the armeabi-v7a folder from the library and xwalk_core_library_java_app_part.jar and xwalk_core_library_java_library_part.jar both of these are included in the dependencies. I don't know whether I should only use one of those jar's? I couldn't find anything about it in any documents.
2) the activity with XWalkView has android:hardwareAccelerated="true"
3) on the crosswalk downloads page (https://crosswalk-project.org/documentation/downloads.html) I have downloaded version 11.40.277.7 of Android webview (ARM)
4) I also merged the "res" folder from crosswalk into my project, but this makes no difference.
5) I've also tried programmatic inflation, however, it also excepts just with a new XWalkView(mParentActivity, mParentActivity); (I know, silly constructor):
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Use SharedXWalkView if you want to support shared mode
at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:233)
at org.xwalk.core.ReflectionHelper.handleException(ReflectionHelper.java:237)
at org.xwalk.core.ReflectionHelper.init(ReflectionHelper.java:132)
at org.xwalk.core.ReflectionHelper.loadClass(ReflectionHelper.java:199)
at org.xwalk.core.ReflectionHelper$ConstructorHelper.loadConstructor(ReflectionHelper.java:37)
at org.xwalk.core.ReflectionHelper.createInstance(ReflectionHelper.java:246)
at org.xwalk.core.XWalkView.<init>(XWalkView.java:192)
For inspiration, I've looked at https://crosswalk-project.org/apis/embeddingapidocs/reference/org/xwalk/core/XWalkView.html however, it's no help on this issue.
Maybe this will help you:
At first i also tried to use jars in my app. That didn't work and i got the same exceptions as you.
Then i stumbled upon this sample app that shows how to use Crosswalk.
I then copied the build into my app and everything worked ok.
Here is what i added in my gradle file:
in the repositories section i added one line (below the crashlytics..)
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven'}
maven { url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'}
}
In the dependencies section i also added one line - the last one:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'org.xwalk:xwalk_core_library:10.39.235.15'
}
This is the xml for the activity:
<org.xwalk.core.XWalkView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/walk_view"
android:layout_width="fill_parent"
android:background="#000000"
android:layout_height="fill_parent"
/>
And this is how i use it in the java code:
private void setXView(){
mXview = (XWalkView)findViewById(R.id.walk_view);
mXview.load("http://www.cnn.com",null);
}
Don't forget to delete the jars in your app or you might get a compilation error if you have fileTree(dir: 'libs', include: ['*.jar']) in your dependencies.
After a day of insane experimentation, I finally gave up on trying to store a local copy of the library.
Instead, I went with Maven using these instructions: https://crosswalk-project.org/documentation/embedding_crosswalk/crosswalk_aar.html
At the bottom of that page is a link to a sample app that's set up with Maven - which is useful.
Note: to find out what versions of the library are available, go here: https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library/
for example, instead of the "beta" dependency, you would have compile 'org.xwalk:xwalk_core_library:12.41.296.5'
After having it set up with maven, I then reverted to the XML inflation.
However, I was then faced with
04-02 16:38:31.036 14165-14165/com.bean.project W/System.err﹕ Caused by: java.lang.ClassCastException: android.view.ContextThemeWrapper cannot be cast to android.app.Activity
04-02 16:38:31.037 14165-14165/com.bean.project W/System.err﹕ at org.xwalk.core.internal.XWalkViewInternal.<init>(XWalkViewInternal.java:197)
04-02 16:38:31.037 14165-14165/com.bean.project W/System.err﹕ at org.xwalk.core.internal.XWalkViewBridge.<init>(XWalkViewBridge.java:46)
the insanity continues...
public XWalkViewInternal(Context context, AttributeSet attrs) {
super(convertContext(context), attrs);
checkThreadSafety();
mActivity = (Activity) context;
mContext = getContext();
init(mContext, attrs);
}
how can they possibly think that's a good idea ??!! /facepalm
EDIT: to get the XWalkView added to a layout programmatically I put a placeholder (empty) RelativeLayout in the XML with ID FULLSCREEN_YOUTUBE_CONTAINER_ID and then in onCreate() of the activity I did:
mYoutubeVideoViewContainer = (RelativeLayout) mLayoutView.findViewById(FULLSCREEN_YOUTUBE_CONTAINER_ID);
mYoutubeWebView = new XWalkView(mParentActivity, mParentActivity);
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mYoutubeVideoViewContainer.addView(mYoutubeWebView, relativeParams);

SlidingUpPanelLayout conflicting with Robolectric

I have a project that uses the SlidingUpPanelLayout but I needed to start writing automated tests using Robolectric. When I introduced Robolectric to the project my Espresso based tests failed to start up. I would get an java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation when the system would try and inflate the SlidingUpPanelLayout.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.marcthomas.testrobolectric/com.marcthomas.testrobolectric.MyActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class com.sothree.slidinguppanel.SlidingUpPanelLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class com.sothree.slidinguppanel.SlidingUpPanelLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1929)
at com.marcthomas.testrobolectric.MyActivity.onCreate(MyActivity.java:14)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentation.callActivityOnCreate(GoogleInstrumentation.java:428)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
... 23 more
Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
at com.sothree.slidinguppanel.ViewDragHelper.<init>(ViewDragHelper.java:392)
at com.sothree.slidinguppanel.ViewDragHelper.create(ViewDragHelper.java:348)
at com.sothree.slidinguppanel.ViewDragHelper.create(ViewDragHelper.java:361)
at com.sothree.slidinguppanel.SlidingUpPanelLayout.<init>(SlidingUpPanelLayout.java:334)
at com.sothree.slidinguppanel.SlidingUpPanelLayout.<init>(SlidingUpPanelLayout.java:263)
... 26 more
If I remove the SlidingUpPanelLayout from my activity_my.xml layout file in the project the tests will run successfully again, so it does seem to be something to do with these two components somehow.
I have created a demo project on github that demonstrates this behaviour. Cloning the code and running ./gradlew connectedAndroidTest will reproduce this issue.
To fix this I needed to add
exclude module: 'support-v4'
to the list of excludes in the app module gradle file where androidTestCompile for robolectric is declared. See explanation below.
This error was down to a Gradle configuration error. The reason is that there are dependencies declared multiple times in the build and one of them needs to be excluded.
To work this out look at the last part of the exception.
ViewDragHelper was the culprit so if in your IDE (Android Studio) open the search for class name (Command-O in OS X) and enter ViewDragHelper. You will see that there are multiple Jars that are returned. You will need to exclude the one that you don’t want.
In this situation we had the android-19 sdk, support-v4-19 and support-v4-20 and library-2.0.1 (the slideuppanellayout library) to solve this I needed to exclude support-v4.
So in the build gradle file for the project where I included robolectric I needed to add the following to the list of excludes.
exclude module: 'support-v4'

Admob android studio, crashing app

I have put the admob .jar file in my project via project structure:
And I added code in for the admob banner into my layout files:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e5e5e5"
android:orientation="vertical" >
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="taken out for stack"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
<ListView
android:id="#+id/yourTasteStatistics"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="0px"
android:divider="#null"
>
</ListView>
</LinearLayout>
But when I open a fragment with an ad on it, my app automatically crashes...Any ideas what step I must be missing here?
Here is the output:
05-13 17:56:44.053 12606-12606/com.beerportfolio.freeBP E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.beerportfolio.freeBP, PID: 12606
android.view.InflateException: Binary XML file line #14: Error inflating class com.google.ads.AdView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at com.beerportfolio.freeBP.BeerPage.onCreateView(BeerPage.java:30)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1097)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1895)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1514)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: DexPathList[[zip file "/data/app/com.beerportfolio.freeBP-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.beerportfolio.freeBP-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java)
at java.lang.ClassLoader.loadClass(ClassLoader.java)
at java.lang.ClassLoader.loadClass(ClassLoader.java)
at android.view.LayoutInflater.createView(LayoutInflater.java)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java)
            at android.view.LayoutInflater.inflate(LayoutInflater.java)
            at android.view.LayoutInflater.inflate(LayoutInflater.java)
            at com.beerportfolio.freeBP.BeerPage.onCreateView(BeerPage.java:30)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1097)
            at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1895)
            at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1514)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
            at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
            at android.os.Handler.handleCallback(Handler.java)
            at android.os.Handler.dispatchMessage(Handler.java)
            at android.os.Looper.loop(Looper.java)
            at android.app.ActivityThread.main(ActivityThread.java)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
            at dalvik.system.NativeStart.main(Native Method)
Line 30 is just where the fragments view is inflated. Make sense its crashing there if it does not like my admob ads.
Update:
As noted in the comments I was using out of date libs. I then followed this link for instructions on how to update to use google play services instead.
https://developer.android.com/google/play-services/setup.html?hl=pt-br
My problem is here on this step:
apply plugin: 'android'
...
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.3.23'
}
When I add that to my grade the gradle fails to sync. My grade looks like this now:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
compile 'com.google.android.gms:play-services:4.3.23'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And give me this error:
Error:(9, 0) Build script error, unsupported Gradle DSL method found: 'compile()'!
Possible causes could be:
- you are using Gradle version where the method is absent (Fix Gradle settings)
- you didn't apply Gradle plugin which provides the method (Apply Gradle plugin)
- or there is a mistake in a build script (Goto source)
Your dependencies block is in the wrong place. It looks like you edited build.gradle in your top level directory.
Open the one in your application module instead. There should be an android block there etc. Or just use the project structure dialog in android studio to edit it.

Dagger code giving NoClassDefFoundError in Android instrumentation tests, but works in the normal application

I am using Dagger in an Android application.
It is working in the Application but when I run the instrumentation tests, I am getting a NoClassDefFoundError.
I am using Gradle and Espresso. This is happening WITHOUT progaurd.
This is strange since the "Module$$ModuleAdapter" getting loaded , but "Module$$ModuleAdapter$EndpointProvidesAdapter" is not.
I pulled the APK back off the device and used dexdump to verify that the class is indeed in the APK, "Module$$ModuleAdapter$EndpointProvidesAdapter".
Any ideas on what might be causing this?
java.lang.NoClassDefFoundError: Module$$ModuleAdapter$EndpointProvidesAdapter
at ...Module$$ModuleAdapter.getBindings(MslModule$$ModuleAdapter.java:33)
at ...Module$$ModuleAdapter.getBindings(MslModule$$ModuleAdapter.java:13)
at dagger.ObjectGraph$DaggerObjectGraph.makeGraph(ObjectGraph.java:185)
at dagger.ObjectGraph$DaggerObjectGraph.access$000(ObjectGraph.java:138)
at dagger.ObjectGraph.create(ObjectGraph.java:129)
at ...Application.onCreate(...Application.java:21)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class ...Module$$ModuleAdapter$MslEndpointProvidesAdapter" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/....test-1.apk", zip file "/data/app/...-2.apk"],nativeLibraryDirectories=[/data/app-lib/....test-1, /data/app-lib/...-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
            at ...Module$$ModuleAdapter.getBindings(MslModule$$ModuleAdapter.java:33)
            at ...Module$$ModuleAdapter.getBindings(MslModule$$ModuleAdapter.java:13)
            at dagger.ObjectGraph$DaggerObjectGraph.makeGraph(ObjectGraph.java:185)
            at dagger.ObjectGraph$DaggerObjectGraph.access$000(ObjectGraph.java:138)
            at dagger.ObjectGraph.create(ObjectGraph.java:129)
            at ...eApplication.onCreate(...Application.java:21)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
            at android.app.ActivityThread.access$1500(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
Double Espresso is now deprecated in favor of Espresso 2.0. It's possible that it worked for you because Jake's done a good job of enumerating transitive dependencies that you may need to exclude in order to get things working.
In my experience, using Espresso 2.0 with Dagger may require you to exclude javax.inject from your espresso dependencies:
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') {
exclude group: 'javax.inject'
}
You may need to do this for all of the espresso dependencies that your project includes.
This seems to be more related to the way I was including Espresso than it is a Dagger issue...
androidTestCompile ('com.google.android.apps.common.testing:espresso:1.1' ){
exclude group: 'com.squareup.dagger'
}
Switching to Jake Wharton's "double-espresso" made the problem go away.
https://github.com/JakeWharton/double-espresso
I am still not sure why that would cause a NoClassDefFoundError on that Dagger generated class.

Categories

Resources