OutOfMemoryError occurs using YouTube Android player api 1.2.2 - android

Play video using youtube player sdk about 30~40 times causes Youtube application crashes, then a DeadObjectException will raise from my app due to the death of remote process. steps to reproduce:
launch activity and initialize YouTubePlayer
load and play a video for a few seconds
release YouTubePlayer and exit activity
repeat step 1-3 about 30~40 times
OutOfMemoryError log(full logs):
08-22 12:01:01.461 E/AndroidRuntime( 3017): FATAL EXCEPTION: main
08-22 12:01:01.461 E/AndroidRuntime( 3017): Process: com.google.android.youtube.player, PID: 3017
08-22 12:01:01.461 E/AndroidRuntime( 3017): java.lang.OutOfMemoryError: Could not allocate JNI Env
08-22 12:01:01.461 E/AndroidRuntime( 3017): at java.lang.Thread.nativeCreate(Native Method)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at java.lang.Thread.start(Thread.java:1063)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:921)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1556)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:310)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:527)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:616)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at reo.a(SourceFile:134)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at sgh.a(SourceFile:722)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at gan.a(SourceFile:310)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at gan.b(SourceFile:338)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at com.google.android.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerService$2.run(SourceFile:215)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at android.os.Handler.handleCallback(Handler.java:739)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at android.os.Handler.dispatchMessage(Handler.java:95)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at android.os.Looper.loop(Looper.java:148)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at android.app.ActivityThread.main(ActivityThread.java:5417)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at java.lang.reflect.Method.invoke(Native Method)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
08-22 12:01:01.461 E/AndroidRuntime( 3017): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
and DeadObjectException
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): java.lang.IllegalStateException: android.os.DeadObjectException
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at gix.surfaceCreated(SourceFile:189)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.view.SurfaceView.updateWindow(SurfaceView.java:582)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:177)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2055)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.view.Choreographer.doCallbacks(Choreographer.java:670)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.view.Choreographer.doFrame(Choreographer.java:606)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.os.Handler.handleCallback(Handler.java:739)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.os.Handler.dispatchMessage(Handler.java:95)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.os.Looper.loop(Looper.java:148)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.app.ActivityThread.main(ActivityThread.java:5417)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at java.lang.reflect.Method.invoke(Native Method)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): Caused by: android.os.DeadObjectException
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.os.BinderProxy.transactNative(Native Method)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at android.os.BinderProxy.transact(Binder.java:503)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at com.google.android.apps.youtube.embeddedplayer.service.service.jar.ISurfaceHolderService$Stub$Proxy.a(SourceFile:110)
08-22 12:01:01.842 E/MonitoringInstrumentation( 2976): at gix.surfaceCreated(SourceFile:186)
YouTube App version is 11.29.55 , Nexus 5 emulator with Marshmallow
, I've tested it with other versions of YouTube App like 10.25.57 and 10.40.58, the OOM still occurs.
At the very beginning when I encounter this issue I thought it was just caused by some incorrectly api method calls, but after so many hours research I figured out it should be a YouTube App's issue, hope someone can help me to resolve it, or at least avoid it.
The memory of process com.google.android.youtube.player is increasing while player initialization and video playing from Memory Monitor, and many YoutubeService instances created but not recycled from the dump file. Any idea?
I test it with a demo application based on the official YouTubeAndroidAPI sample and the OutOfMemory error occurs as well, I just replaced cueVideo(String) by loadVideo(String) in PlayerViewDemoActivity for auto-playing, and added YouTubePlayer#release() in onDestroy(), also I added a test code based on Espresso to reproduce the memory leak issue.
here is the test code, and here for full demo code.
package com.examples.youtubeapidemo.play;
import android.os.SystemClock;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;
import com.examples.youtubeapidemo.YouTubeAPIDemoActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.pressBack;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
/**
* for YouTubePlayerView testing
*/
#RunWith(AndroidJUnit4.class)
#LargeTest
public class PlayerViewTest {
#Rule
public ActivityTestRule<YouTubeAPIDemoActivity> mActivityTestRule =
new ActivityTestRule<YouTubeAPIDemoActivity>(YouTubeAPIDemoActivity.class);
#Test
public void testYouTubeMemoryLeaks() {
int count = 0;
while(count < 100) {
onView(withText("Simple PlayerView")).perform(click());
SystemClock.sleep(10000); // waiting for video start playing
pressBack();
count++;
Log.i("PlayerViewTest", "count: " + count);
}
}
}

I reduced the bug occurrence by putting youtube calls (like youtubePlayer.loadVideo(), cueVideo(), getCurrentTimeMillis() etc.) in a try catch block and catch the IllegalStateException exception then reinitialize youtube player.
and worked around it by catching these exceptions and restart activity,
see my answer on this thread :
Getting a lot of crashes from android youtube player api

Related

ActivityNotFoundException in library projecy while the Activity is there and is declared in Manifest

I am trying to use this library. But the library project as well as the demo project on the github page is for Android Studio, but for some reason I use Eclipse. So I added the library and the demo project to Eclipse (see below for how I did that) and uploaded them here:
customsearchable - library Eclipse project
demo - demo Eclipse project
So what I did was that I created a new library project in Eclipse and copied all the files from the github library project. Following screenshot shows my project structure:
I added this library project to my demo project just like we add the app_compat v7 project.
Then I went on the create a demo project in Eclipse and copied all the files and resources from the demo project in their github repository.
But when I run it, it gives me android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.edsilfer/br.com.customsearchable.SearchActivity}; have you declared this activity in your AndroidManifest.xml?
Following are the Logcat of the demo project, and the manifest of the library project:
FROM LOGCAT OF DEMO PROJECT:
08-22 02:53:26.110: E/AndroidRuntime(2405): FATAL EXCEPTION: main
08-22 02:53:26.110: E/AndroidRuntime(2405): Process: br.com.edsilfer, PID: 2405
08-22 02:53:26.110: E/AndroidRuntime(2405): android.content.ActivityNotFoundException: Unable to find explicit activity class {br.com.edsilfer/br.com.customsearchable.SearchActivity}; have you declared this activity in your AndroidManifest.xml?
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.app.Activity.startActivityForResult(Activity.java:3745)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.app.Activity.startActivityForResult(Activity.java:3706)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.app.Activity.startActivity(Activity.java:4016)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.app.Activity.startActivity(Activity.java:3984)
08-22 02:53:26.110: E/AndroidRuntime(2405): at br.com.edsilfer.Main.onOptionsItemSelected(Main.java:82)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.app.Activity.onMenuItemSelected(Activity.java:2885)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:353)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:144)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v7.internal.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:99)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v7.app.AppCompatDelegateImplV7.onMenuItemSelected(AppCompatDelegateImplV7.java:541)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v7.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v7.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:153)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v7.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:948)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:598)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.support.v7.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:139)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.view.View.performClick(View.java:4780)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.view.View$PerformClick.run(View.java:19866)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.os.Handler.handleCallback(Handler.java:739)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.os.Handler.dispatchMessage(Handler.java:95)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.os.Looper.loop(Looper.java:135)
08-22 02:53:26.110: E/AndroidRuntime(2405): at android.app.ActivityThread.main(ActivityThread.java:5254)
08-22 02:53:26.110: E/AndroidRuntime(2405): at java.lang.reflect.Method.invoke(Native Method)
08-22 02:53:26.110: E/AndroidRuntime(2405): at java.lang.reflect.Method.invoke(Method.java:372)
08-22 02:53:26.110: E/AndroidRuntime(2405): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
08-22 02:53:26.110: E/AndroidRuntime(2405): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
MANIFEST OF LIB PROJECT:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.customsearchable">
<uses-sdk
android:minSdkVersion="22"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<activity android:name="br.com.customsearchable.SearchActivity"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize|stateVisible"
android:theme="#style/Theme.AppCompat.Translucent" >
</activity>
</application>
</manifest>
EDIT # 1
After being pointed to this question by #MFaisalHyder I added the following element to the <application> element of the demo project:
<activity android:name="br.com.customsearchable.SearchActivity"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize|stateVisible"
android:theme="#style/Theme.AppCompat.Translucent" >
</activity>
Now, after touching the Search action from the toolbar, I get:
08-22 04:44:31.332: E/AndroidRuntime(2104): FATAL EXCEPTION: main
08-22 04:44:31.332: E/AndroidRuntime(2104): Process: br.com.edsilfer, PID: 2104
08-22 04:44:31.332: E/AndroidRuntime(2104): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.edsilfer/br.com.customsearchable.SearchActivity}: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.TextInputLayout
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.app.ActivityThread.access$800(ActivityThread.java:151)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.os.Handler.dispatchMessage(Handler.java:102)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.os.Looper.loop(Looper.java:135)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.app.ActivityThread.main(ActivityThread.java:5254)
08-22 04:44:31.332: E/AndroidRuntime(2104): at java.lang.reflect.Method.invoke(Native Method)
08-22 04:44:31.332: E/AndroidRuntime(2104): at java.lang.reflect.Method.invoke(Method.java:372)
08-22 04:44:31.332: E/AndroidRuntime(2104): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
08-22 04:44:31.332: E/AndroidRuntime(2104): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
08-22 04:44:31.332: E/AndroidRuntime(2104): Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.TextInputLayout
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
08-22 04:44:31.332: E/AndroidRuntime(2104): at br.com.customsearchable.SearchActivity.onCreate(SearchActivity.java:66)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.app.Activity.performCreate(Activity.java:5990)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
08-22 04:44:31.332: E/AndroidRuntime(2104): ... 10 more
08-22 04:44:31.332: E/AndroidRuntime(2104): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.TextInputLayout" on path: DexPathList[[zip file "/data/app/br.com.edsilfer-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
08-22 04:44:31.332: E/AndroidRuntime(2104): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
08-22 04:44:31.332: E/AndroidRuntime(2104): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-22 04:44:31.332: E/AndroidRuntime(2104): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.view.LayoutInflater.createView(LayoutInflater.java:571)
08-22 04:44:31.332: E/AndroidRuntime(2104): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
08-22 04:44:31.332: E/AndroidRuntime(2104): ... 22 more
08-22 04:44:31.332: E/AndroidRuntime(2104): Suppressed: java.lang.ClassNotFoundException: android.support.design.widget.TextInputLayout
08-22 04:44:31.332: E/AndroidRuntime(2104): at java.lang.Class.classForName(Native Method)
08-22 04:44:31.332: E/AndroidRuntime(2104): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
08-22 04:44:31.332: E/AndroidRuntime(2104): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
08-22 04:44:31.332: E/AndroidRuntime(2104): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
08-22 04:44:31.332: E/AndroidRuntime(2104): ... 25 more
08-22 04:44:31.332: E/AndroidRuntime(2104): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
EDIT # 2
The above error was resolved by adding the <activity> element for the SearchActivity in my project's Manifest. Now I am getting android.view.InflateException: Error Inflating class android.support.design.widget.TextInputLayout. I have added the design library. Below you can see the logcat for the exception and the project properties for the design library project
Logcat
08-22 05:44:34.827: E/AndroidRuntime(2582): FATAL EXCEPTION: main
08-22 05:44:34.827: E/AndroidRuntime(2582): Process: br.com.edsilfer, PID: 2582
08-22 05:44:34.827: E/AndroidRuntime(2582): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.edsilfer/br.com.customsearchable.SearchActivity}: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.TextInputLayout
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.app.ActivityThread.access$800(ActivityThread.java:151)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.os.Handler.dispatchMessage(Handler.java:102)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.os.Looper.loop(Looper.java:135)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.app.ActivityThread.main(ActivityThread.java:5254)
08-22 05:44:34.827: E/AndroidRuntime(2582): at java.lang.reflect.Method.invoke(Native Method)
08-22 05:44:34.827: E/AndroidRuntime(2582): at java.lang.reflect.Method.invoke(Method.java:372)
08-22 05:44:34.827: E/AndroidRuntime(2582): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
08-22 05:44:34.827: E/AndroidRuntime(2582): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
08-22 05:44:34.827: E/AndroidRuntime(2582): Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.TextInputLayout
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.view.LayoutInflater.createView(LayoutInflater.java:633)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
08-22 05:44:34.827: E/AndroidRuntime(2582): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
08-22 05:44:34.827: E/AndroidRuntime(2582): at br.com.customsearchable.SearchActivity.onCreate(SearchActivity.java:66)
...
08-22 05:44:34.827: E/AndroidRuntime(2582): Caused by: java.lang.reflect.InvocationTargetException
...
08-22 05:44:34.827: E/AndroidRuntime(2582): Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/design/R$styleable;
...
...
java.lang.ClassNotFoundException: android.support.design.R$styleable
...
08-22 05:44:34.827: E/AndroidRuntime(2582): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
EDIT 4:
After deleting (from the emulator) and reinstalling the app, it works somehow, i.e. there is no exception in the appearance of the activity, but the voice search and search suggestions still don't work. =/
Maybe, the launcher intent filter is missing...
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<activity android:name="br.com.customsearchable.SearchActivity"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize|stateVisible"
android:theme="#style/Theme.AppCompat.Translucent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Try with this, and let me know if it works.
check these two links for help :
One and this one.
Before using any activity of Library Project its every activity and other parts must be declared in the Manifest file.
For your Intent part try like this:
Intent i = new Intent();
i.setClassName("base.package.name.of.your.app","br.com.customsearchable.SearchActivity");
startActivity(i);
//*****Another way******\\
Intent i = new Intent(getApplicationContext(),br.com.customsearchable.SearchActivity.class);
startActivity(i);
One more thing: some people also found that it is the problem of Eclipse (Like this one) so do try to update Eclipse.
Hope i helped you.!
Actually the error you are facing,because of missing design support library.
you can follow the steps to import.
go to the properties of your design library>>select android>>check android version 5.0 or above>> check is library>>add library appcompat_v7>> click apply and ok

App crashing on particular Android version

I am working on an Android application. when I run my App below api 16 it works fine but when it runs on a post api 16 phone it crashes. Here is a the logact log which appears when it crashes.
06-19 20:20:05.096 5812-5812/com.ets.medecord W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x42011898)
06-19 20:20:05.106 5812-5812/com.ets.medecord E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ets.medecord/com.ets.medecord.SignupActivity2}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2268)
at android.app.ActivityThread.access$600(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5162)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:756)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:572)
at miui.dexspy.DexspyInstaller.main(DexspyInstaller.java:171)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.ets.medecord.SignupActivity2.onCreate(SignupActivity2.java:72)
at android.app.Activity.performCreate(Activity.java:5135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at com.lbe.security.service.core.client.b.x.callActivityOnCreate(Unknown Source)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2182)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2268)
            at android.app.ActivityThread.access$600(ActivityThread.java:148)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5162)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:756)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:572)
            at miui.dexspy.DexspyInstaller.main(DexspyInstaller.java:171)
            at dalvik.system.NativeStart.main(Native Method)
To see code of the activity you can checkout this gist https://gist.github.com/darthvish/873dc292c841e5c86312
As you are using some deprecated features, so it may not supported for some API levels. For this you can check the api level as well as version before using the deprecated features using if condition. For example :
if(Build.VERSION.RELEASE.equals("4.4.4")) {
//Do somthing
}

Robotium with support.v4 ViewCompat throws NoSuchMethodError on load

I'm using Robotium to automate my app testing. My app has 1 activity (ActionBarActivity) and 2 fragments (using support.v4.app.Fragment). The app works fine but when I attempt to run a Robotium test, I get an error when attempting to create a new Solo instance.
solo = new Solo(getInstrumentation(), getActivity());
Logcat output:
java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V in class Landroid/support/v4/view/ViewCompat; or its super classes (declaration of 'android.support.v4.view.ViewCompat' appears in /data/app/com.mycompany.mytrip.test-1/base.apk)
E/AndroidRuntime( 5220): at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:304)
E/AndroidRuntime( 5220): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:225)
E/AndroidRuntime( 5220): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
E/AndroidRuntime( 5220): at com.mycompany.mytrip.activities.MainActivity.onCreate(MainActivity.java:38)
E/AndroidRuntime( 5220): at android.app.Activity.performCreate(Activity.java:5933)
E/AndroidRuntime( 5220): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime( 5220): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
E/AndroidRuntime( 5220): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
E/AndroidRuntime( 5220): at android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime( 5220): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
E/AndroidRuntime( 5220): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 5220): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 5220): at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime( 5220): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5220): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 5220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime( 5220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
W/ActivityManager( 1229): Error in app com.mycompany.mytrip running instrumentation ComponentInfo{com.mycompany.mytrip.test/android.test.InstrumentationTestRunner}:
W/ActivityManager( 1229): java.lang.NoSuchMethodError
W/ActivityManager( 1229): java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V in class Landroid/support/v4/view/ViewCompat; or its super classes (declaration of 'android.support.v4.view.ViewCompat' appears in /data/app/com.mycompany.mytrip.test-1/base.apk)
D/AndroidRuntime( 5209): Shutting down VM
Any suggestion much appreciated!

Configuring Tesseract in Android

I am facing a very weird problem while configuring Tesseract in Android. Following all required steps described here and SO like this and this i have imported tess-two library in eclipse. NDK-build and ant release was also successfull. I have used latest ndk version and android sdk v19(4.4.2).
Next, i had imported a sample project in eclipse written in above blog. All were build successfully. But, when i run the project in a real device, it gives me such a weird error in onPhotoTaken event that possible google search can't answer me nothing!
Logcat says:
08-22 15:04:44.812: V/SimpleAndroidOCR.java(16578): Before baseApi
08-22 15:04:44.812: D/dalvikvm(16578): Trying to load lib /data/app-lib/com.datumdroid.android.ocr.simple-1/liblept.so 0x41e56b50
08-22 15:04:44.822: D/dalvikvm(16578): GC_CONCURRENT freed 1K, 14% free 4989K/5788K, paused 2ms+2ms, total 18ms
08-22 15:04:44.822: E/dalvikvm(16578): dlopen("/data/app-lib/com.datumdroid.android.ocr.simple-1/liblept.so") failed: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "rand" referenced by "liblept.so"...
08-22 15:04:44.832: W/dalvikvm(16578): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI;
08-22 15:04:44.832: D/AndroidRuntime(16578): Shutting down VM
08-22 15:04:44.832: W/dalvikvm(16578): threadid=1: thread exiting with uncaught exception (group=0x41be0930)
08-22 15:04:44.832: E/AndroidRuntime(16578): FATAL EXCEPTION: main
08-22 15:04:44.832: E/AndroidRuntime(16578): java.lang.ExceptionInInitializerError
08-22 15:04:44.832: E/AndroidRuntime(16578): at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onPhotoTaken(SimpleAndroidOCRActivity.java:211)
08-22 15:04:44.832: E/AndroidRuntime(16578): at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onActivityResult(SimpleAndroidOCRActivity.java:135)
08-22 15:04:44.832: E/AndroidRuntime(16578): at android.app.Activity.dispatchActivityResult(Activity.java:5302)
08-22 15:04:44.832: E/AndroidRuntime(16578): at android.app.ActivityThread.deliverResults(ActivityThread.java:3315)
08-22 15:04:44.832: E/AndroidRuntime(16578): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2729)
08-22 15:04:44.832: E/AndroidRuntime(16578): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
08-22 15:04:44.832: E/AndroidRuntime(16578): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
08-22 15:04:44.832: E/AndroidRuntime(16578): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-22 15:04:44.832: E/AndroidRuntime(16578): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-22 15:04:44.832: E/AndroidRuntime(16578): at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 15:04:44.832: E/AndroidRuntime(16578): at android.os.Looper.loop(Looper.java:137)
08-22 15:04:44.832: E/AndroidRuntime(16578): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-22 15:04:44.832: E/AndroidRuntime(16578): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 15:04:44.832: E/AndroidRuntime(16578): at java.lang.reflect.Method.invoke(Method.java:511)
08-22 15:04:44.832: E/AndroidRuntime(16578): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
08-22 15:04:44.832: E/AndroidRuntime(16578): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
08-22 15:04:44.832: E/AndroidRuntime(16578): at dalvik.system.NativeStart.main(Native Method)
08-22 15:04:44.832: E/AndroidRuntime(16578): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "rand" referenced by "liblept.so"...
08-22 15:04:44.832: E/AndroidRuntime(16578): at java.lang.Runtime.loadLibrary(Runtime.java:371)
08-22 15:04:44.832: E/AndroidRuntime(16578): at java.lang.System.loadLibrary(System.java:535)
08-22 15:04:44.832: E/AndroidRuntime(16578): at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:44)
08-22 15:04:44.832: E/AndroidRuntime(16578): ... 17 more
Probably the most important part of this error message is:
08-22 15:04:44.832: E/AndroidRuntime(16578): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "rand" referenced by "liblept.so"...
I checked liblept.so is inside the libs folder of library project that i referenced in my sample project.
Can anyone point me the solution or suggestion of this time-killing problem? Thanks in advance.
There seems to be a problem with the NDK toolchain version 4.9.
Try pulling the latest version of the tess-two library code, which includes the following in its Application.mk:
NDK_TOOLCHAIN_VERSION := 4.8
You will need to use the "ndk32" version of the NDK for 32-bit targets.

Error: You do not have read/write permission to the serial port

I have sample application to read from serial port from here.
I have set device to ttyUSB1(usbserial) and Baud rate to 9600 .
but when I click on console I am getting Error: You do not have read/write permission to the serial port
my logcat is
08-22 15:01:25.210: W/System.err(14524): java.io.IOException: Error running exec(). Command:
[/system/bin/su] Working Directory: null Environment: null
08-22 15:01:25.210: W/System.err(14524): at
java.lang.ProcessManager.exec(ProcessManager.java:211)
08-22 15:01:25.211: W/System.err(14524): at java.lang.Runtime.exec(Runtime.java:168)
08-22 15:01:25.211: W/System.err(14524): at java.lang.Runtime.exec(Runtime.java:241)
08-22 15:01:25.212: W/System.err(14524): at java.lang.Runtime.exec(Runtime.java:184)
08-22 15:01:25.212: W/System.err(14524): at android_serialport_api.SerialPort.<init>
(SerialPort.java:47)
08-22 15:01:25.212: W/System.err(14524): at
android_serialport_api.sample.Application.getSerialPort(Application.java:46)
08-22 15:01:25.213: W/System.err(14524): at
android_serialport_api.sample.SerialPortActivity.onCreate(SerialPortActivity.java:78)
08-22 15:01:25.213: W/System.err(14524): at
android_serialport_api.sample.Sending01010101Activity.onCreate(Sending01010101Activity.java:31)
08-22 15:01:25.214: W/System.err(14524): at
android.app.Activity.performCreate(Activity.java:5020)
08-22 15:01:25.214: W/System.err(14524): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-22 15:01:25.214: W/System.err(14524): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
08-22 15:01:25.214: W/System.err(14524): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
08-22 15:01:25.215: W/System.err(14524): at
android.app.ActivityThread.access$600(ActivityThread.java:149)
08-22 15:01:25.215: W/System.err(14524): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
08-22 15:01:25.215: W/System.err(14524): at
android.os.Handler.dispatchMessage(Handler.java:99)
08-22 15:01:25.216: W/System.err(14524): at android.os.Looper.loop(Looper.java:153)
08-22 15:01:25.216: W/System.err(14524): at
android.app.ActivityThread.main(ActivityThread.java:4987)
08-22 15:01:25.216: W/System.err(14524): at java.lang.reflect.Method.invokeNative(Native
Method)
08-22 15:01:25.216: W/System.err(14524): at java.lang.reflect.Method.invoke(Method.java:511)
08-22 15:01:25.217: W/System.err(14524): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
08-22 15:01:25.217: W/System.err(14524): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
08-22 15:01:25.217: W/System.err(14524): at dalvik.system.NativeStart.main(Native Method)
08-22 15:01:25.217: W/System.err(14524): Caused by: java.io.IOException: No such file or
directory
08-22 15:01:25.218: W/System.err(14524): at java.lang.ProcessManager.exec(Native Method)
08-22 15:01:25.219: W/System.err(14524): at
java.lang.ProcessManager.exec(ProcessManager.java:209)
08-22 15:01:25.219: W/System.err(14524): ... 21 more
How can I resolve this.
please help to solve this.
If you are using serial port application go to file SerialPort.java
change the line:
su = Runtime.getRuntime().exec("/system/bin/su");
to
su = Runtime.getRuntime().exec("/system/xbin/su");
Error: You do not have read/write permission to the serial port
Just change bin to xbin.
like this, Runtime.getRuntime().exec("/system/xbin/su");

Categories

Resources