So I wrote an instrumental test that performs some changes in my database on my localhost server. I used just jdbc raw query, nothing special.
On Android < 5.0 instrumental tests run ok
On Android starting from 5.0 (doesn't matter if it's an emulator or real device) instrumentalTests classLoader throws java.lang.NoClassDefFoundError: com.mysql.jdbc.jdbc2.optional.MysqlDataSource. Note my tests do not even start.
I do have mysql in dependencies and I don't use proguard in debug mode that can strip it out.
If I specify mysql-connector-java as compile instead of androidTestCompile it works after android 5.0 as well. So the problem is androidTestCompile doesn't append mysql lib to instrumental environment.
Why does android 5.0 doesn't detect androidTestCompile dependency? Here's what I got:
build.gradle:
dependencies {
//...
androidTestCompile "mysql:mysql-connector-java:5.1.6"
}
androidTest/java/my.package.Mytest:
Note that I load mysql lib via Class.forName
import java.sql.*; // some java.sql imports, no mysql dependencies in imports.
#RunWith(AndroidJUnit4.class)
#LargeTest
public class LoginTest {
#Rule
public final ActivityTestRule<MainScreen> main = new ActivityTestRule<>(MainScreen.class);
#Test
public void checkLoginFlow() throws InterruptedException {
// Login/Sign up flow
assertEquals("App is not loaded", MainScreen.class, getCurrentActivity());
Connection conn = null;
PreparedStatement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver");
....
Here's the full log:
Testing started at 1:12 PM ...
01/17 13:12:50: Launching UITest
$ adb push /tmp/MyApp/app/outputs/apk/app-debug.apk /data/local/tmp/com.MyApp
$ adb shell pm install -r "/data/local/tmp/com.MyApp"
pkg: /data/local/tmp/com.MyApp
Success
$ adb push /tmp/MyApp/app/outputs/apk/app-debug-androidTest.apk /data/local/tmp/com.MyApp.test
$ adb shell pm install -r "/data/local/tmp/com.MyApp.test"
pkg: /data/local/tmp/com.MyApp.test
Success
Running tests
$ adb shell am instrument -w -r -e debug true com.MyApp.test/android.support.test.runner.AndroidJUnitRunner
Waiting for application to come online: com.MyApp | com.MyApp.test
Waiting for application to come online: com.MyApp | com.MyApp.test
Waiting for application to come online: com.MyApp | com.MyApp.test
Waiting for application to come online: com.MyApp | com.MyApp.test
Connecting to com.MyApp
I/art: Debugger is active
Connected to the target VM, address: 'localhost:8657', transport: 'socket'
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1434)
I/AndroidJUnitRunner: Debugger connected.
I/MonitoringInstrumentation: Instrumentation Started!
I/MonitoringInstrumentation: Setting context classloader to 'dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.MyApp.test-2/base.apk", zip file "/data/app/com.MyApp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.MyApp.test-2/lib/x86_64, /data/app/com.MyApp-2/lib/x86_64, /vendor/lib64, /system/lib64]]]', Original: 'dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.MyApp.test-2/base.apk", zip file "/data/app/com.MyApp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.MyApp.test-2/lib/x86_64, /data/app/com.MyApp-2/lib/x86_64, /vendor/lib64, /system/lib64]]]'
I/MonitoringInstrumentation: No JSBridge.
I/UsageTrackerFacilitator: Usage tracking enabled
I/TestRequestBuilder: Scanning classpath to find tests in apks [/data/app/com.MyApp.test-2/base.apk]
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.integration.c3p0.MysqlConnectionTester>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.integration.c3p0.MysqlConnectionTester>
E/TestLoader: Could not find class: com.mysql.jdbc.integration.c3p0.MysqlConnectionTester
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter>
E/TestLoader: Could not find class: com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker>
E/TestLoader: Could not find class: com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.MysqlXAConnection>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.MysqlXAConnection>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection>
E/TestLoader: Could not find class: com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.SuspendableXAConnection>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.SuspendableXAConnection>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection>
E/TestLoader: Could not find class: com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.MysqlDataSource>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.MysqlDataSource>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource>
E/TestLoader: Could not find class: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.mysql.jdbc.jdbc2.optional.MysqlDataSource>
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: Instr: android.support.test.runner.AndroidJUnitRunner
Process: com.MyApp, PID: 4088
java.lang.NoClassDefFoundError: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at android.support.test.internal.runner.TestLoader.doLoadClass(TestLoader.java:92)
at android.support.test.internal.runner.TestLoader.loadIfTest(TestLoader.java:113)
at android.support.test.internal.runner.TestRequestBuilder.loadClassesFromClassPath(TestRequestBuilder.java:801)
at android.support.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:747)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:354)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:260)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)
Started running tests
Test running failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'
Tests ran to completion.
Related
I have implemented admob in my app.when the activity loads ,logcat shows some errors which i am not able to relate to admob.
LogCat:
W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
I/art: DexFile_isDexOptNeeded failed to open oat file '/data/dalvik-cache/arm64/data#data#com.google.android.gms#app_chimera#m#00000040#DynamiteModulesA_GmsCore_prodlmp_xhdpi_release.apk#classes.dex' for file location '/data/data/com.google.android.gms/app_chimera/m/00000040/DynamiteModulesA_GmsCore_prodlmp_xhdpi_release.apk': Failed to open oat filename for reading: No such file or directory
D/DynamitePackage: Instantiated singleton DynamitePackage.
D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraMobileAdsSettingManagerCreatorImpl
D/WebViewFactory: primaryArchIs64bit = true
I/WebViewFactory: Loading com.google.android.webview version 64.0.3282.137 (code 328213750)
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
I/cr_LibraryLoader: Time to load native libraries: 2 ms (timestamps 8604-8606)
I/chromium: [INFO:library_loader_hooks.cc(36)] Chromium logging enabled: level = 0, default verbosity = 0
I/cr_LibraryLoader: Expected native library version number "64.0.3282.137", actual native library version number "64.0.3282.137"
I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
I/cr_base: Android Locale: en_IN requires .pak files: []
E/chromium: [ERROR:instance.cc(49)] Unable to locate service manifest for metrics
E/chromium: [ERROR:service_manager.cc(890)] Failed to resolve service name: metrics
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$WebResourceErrorImpl>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$WebResourceErrorImpl>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$7>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$7>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$3>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$3>
D/ConnectivityManager.CallbackHandler: CM callback handler got msg 524290
I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingActionModeCallback>
I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingActionModeCallback>
**W/cr_media: Requires BLUETOOTH permission
E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
D/ConnectivityManager.CallbackHandler: CM callback handler got msg 524290
W/AudioCapabilities: Unsupported mime audio/evrc
W/AudioCapabilities: Unsupported mime audio/qcelp
W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
W/AudioCapabilities: Unsupported mime audio/qcelp
W/AudioCapabilities: Unsupported mime audio/evrc
W/VideoCapabilities: Unsupported mime video/mp4v-esdp
D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es**
I/Ads: Updating ad debug logging enablement.
I/Ads: Starting ad request.
I/Ads: Use AdRequest.Builder.addTestDevice("*********") to get test ads on this device.
W/Ads: Not retrying to fetch app settings
I/Choreographer: Skipped 184 frames! The application may be doing too much work on its main thread.
W/Ads: Invoke Firebase method getInstance error.
W/Ads: The Google Mobile Ads SDK will not integrate with Firebase. Admob/Firebase integration requires the latest Firebase SDK jar, but Firebase SDK is either missing or out of date
D/ConnectivityManager.CallbackHandler: CM callback handler got msg 524290
W/Ads: Update ad debug logging enablement as false
I/chromium: [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
I/chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#3020318e time:246760805
W/cr_CrashFileManager: /data/data/com.sns.kids.maths.games/cache/WebView/Crash Reports does not exist or is not a directory
I/chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
I/Ads: Scheduling ad refresh 70000 milliseconds from now.
I/Ads: Ad finished loading.
I/chromium: [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
I/chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
I/chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
I/chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
I/chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#16ae39cd time:246768461
The logcat says it requires bluetooth permission.I am getting this only when i am adding admob code.When i remove the admob it disappears.
Admob Code :
private void showBannerAds() {
MobileAds.initialize(this,getResources().getString(R.string.admob_appid));
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
I have looked at many, many SO posts to find an answer, but no luck...
How do I send a file from public storage as an e-mail attachment?
Most posts are asking about internal storage files. So for that, they use FileProvider (or something like that). In the docs for FileProvider, I read:
FileProvider ... facilitates secure sharing of files associated with an app...
But the file I want to send is not associated with my app. It is a .csv file in public storage in the Documents folder. So it seems really bizarre for my app to set up a FileProvider with access permissions for a public file. Even more strange to use my package name as the "authority".
I tried the following code, which I put together based on answers in 1 or 2 other posts:
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
File f = new File(path, _sFileName);
_sFileDir = f.getCanonicalPath();
and in another method I have:
Intent i = new Intent(android.content.Intent.ACTION_SEND);
String Email[] = { "my.name#gmail.com" };
i.putExtra(android.content.Intent.EXTRA_EMAIL, Email);
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Report");
i.setType("plain/text");
String sURI = "file:/" + _sFileDir;
i.putExtra(Intent.EXTRA_STREAM, Uri.parse(sURI));
startActivity(i);
This causes the app to crash with the message: "MyApp has stopped"
When I changed "file:/" to "content:/" the app no longer crashed, and the email was sent, but no file was attached.
My AndroidManifest.xml contains the following permissions:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Here is my LogCat from the time when I use "content:/":
07-28 17:19:22.528 27809-27809/? I/art: Late-enabling -Xcheck:jni
07-28 17:19:22.569 27809-27816/? E/art: Failed sending reply to debugger: Broken pipe
07-28 17:19:22.569 27809-27816/? I/art: Debugger is no longer active
07-28 17:19:22.569 27809-27816/? I/art: Starting a blocking GC Instrumentation
07-28 17:19:22.582 27809-27809/? W/ActivityThread: Application com.myorg.myapp is waiting for the debugger on port 8100...
07-28 17:19:22.583 27809-27809/? I/System.out: Sending WAIT chunk
07-28 17:19:24.636 27809-27816/com.myorg.myapp I/art: Debugger is active
07-28 17:19:24.785 27809-27809/com.myorg.myapp I/System.out: Debugger has connected
07-28 17:19:24.785 27809-27809/com.myorg.myapp I/System.out: waiting for debugger to settle...
07-28 17:19:24.985 27809-27809/com.myorg.myapp I/System.out: waiting for debugger to settle...
07-28 17:19:25.186 27809-27809/com.myorg.myapp I/System.out: waiting for debugger to settle...
07-28 17:19:25.386 27809-27809/com.myorg.myapp I/System.out: waiting for debugger to settle...
07-28 17:19:25.588 27809-27809/com.myorg.myapp I/System.out: waiting for debugger to settle...
07-28 17:19:25.788 27809-27809/com.myorg.myapp I/System.out: waiting for debugger to settle...
07-28 17:19:25.989 27809-27809/com.myorg.myapp I/System.out: waiting for debugger to settle...
07-28 17:19:26.189 27809-27809/com.myorg.myapp I/System.out: debugger has settled (1454)
07-28 17:19:26.408 27809-27809/com.myorg.myapp W/System: ClassLoader referenced unknown path: /data/app/com.myorg.myapp-1/lib/arm
07-28 17:19:26.444 27809-27809/com.myorg.myapp I/InstantRun: starting instant run server: is main process
07-28 17:19:26.508 27809-27816/com.myorg.myapp I/art: Starting a blocking GC Instrumentation
07-28 17:19:26.801 27809-27809/com.myorg.myapp W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-28 17:19:28.471 27809-27814/com.myorg.myapp I/art: Do partial code cache collection, code=14KB, data=23KB
07-28 17:19:28.471 27809-27814/com.myorg.myapp I/art: After code cache collection, code=14KB, data=23KB
07-28 17:19:28.471 27809-27814/com.myorg.myapp I/art: Increasing code cache capacity to 128KB
07-28 17:19:28.475 27809-27814/com.myorg.myapp I/art: Do partial code cache collection, code=14KB, data=42KB
07-28 17:19:28.476 27809-27814/com.myorg.myapp I/art: After code cache collection, code=14KB, data=42KB
07-28 17:19:28.476 27809-27814/com.myorg.myapp I/art: Increasing code cache capacity to 256KB
07-28 17:19:29.036 27809-27814/com.myorg.myapp I/art: Do full code cache collection, code=119KB, data=108KB
07-28 17:19:29.037 27809-27814/com.myorg.myapp I/art: After code cache collection, code=113KB, data=86KB
07-28 17:19:29.216 27809-27895/com.myorg.myapp I/Adreno: QUALCOMM build : 7d18700, I8ee426a9a2
Build Date : 10/07/16
OpenGL ES Shader Compiler Version: XE031.09.00.03
Local Branch : mybranch22308589
Remote Branch : quic/LA.BR.1.3.6_rb1.6
Remote Branch : NONE
Reconstruct Branch : NOTHING
07-28 17:19:29.229 27809-27895/com.myorg.myapp I/OpenGLRenderer: Initialized EGL, version 1.4
07-28 17:19:29.229 27809-27895/com.myorg.myapp D/OpenGLRenderer: Swap behavior 1
07-28 17:19:29.388 27809-27814/com.myorg.myapp I/art: Do partial code cache collection, code=125KB, data=105KB
07-28 17:19:29.388 27809-27814/com.myorg.myapp I/art: After code cache collection, code=125KB, data=105KB
07-28 17:19:29.388 27809-27814/com.myorg.myapp I/art: Increasing code cache capacity to 512KB
07-28 17:19:29.691 27809-27809/com.myorg.myapp W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
07-28 17:19:29.701 27809-27809/com.myorg.myapp I/Choreographer: Skipped 97 frames! The application may be doing too much work on its main thread.
07-28 17:19:34.479 27809-27809/com.myorg.myapp I/Choreographer: Skipped 124 frames! The application may be doing too much work on its main thread.
07-28 17:19:37.417 27809-27809/com.myorg.myapp W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
07-28 17:19:37.417 27809-27809/com.myorg.myapp W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
07-28 17:19:41.841 27809-27814/com.myorg.myapp I/art: Do full code cache collection, code=252KB, data=246KB
07-28 17:19:41.844 27809-27814/com.myorg.myapp I/art: After code cache collection, code=248KB, data=216KB
07-28 17:19:45.257 27809-27809/com.myorg.myapp I/Choreographer: Skipped 204 frames! The application may be doing too much work on its main thread.
07-28 17:19:49.125 27809-27809/com.myorg.myapp W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
07-28 17:19:49.126 27809-27809/com.myorg.myapp W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
07-28 17:19:57.498 27809-27814/com.myorg.myapp I/art: Do partial code cache collection, code=250KB, data=227KB
07-28 17:19:57.499 27809-27814/com.myorg.myapp I/art: After code cache collection, code=250KB, data=227KB
07-28 17:19:57.499 27809-27814/com.myorg.myapp I/art: Increasing code cache capacity to 1024KB
07-28 17:20:12.117 27809-27809/com.myorg.myapp W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
07-28 17:20:12.117 27809-27809/com.myorg.myapp W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
Here's another LogCat when "file:/" is used & the app crashes:
07-28 17:43:57.190 30651-30651/com.myorg.myapp D/AndroidRuntime: Shutting down VM
07-28 17:43:57.232 30651-30651/com.myorg.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myorg.myapp, PID: 30651
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5612)
at android.view.View$PerformClick.run(View.java:22285)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
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)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5612)
at android.view.View$PerformClick.run(View.java:22285)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
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)
Caused by: android.os.FileUriExposedException: file://storage/emulated/0/Documents/Tasks.csv exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1813)
at android.net.Uri.checkFileUriExposed(Uri.java:2360)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8957)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8942)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1583)
at android.app.Activity.startActivityForResult(Activity.java:4228)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4187)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4515)
at android.app.Activity.startActivity(Activity.java:4483)
at com.myorg.myapp.MainActivity.onClickSend(ProgSummary.java:209)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5612)
at android.view.View$PerformClick.run(View.java:22285)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
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)
What is the right way to do this?
New Information:
When I used "content:/", this time I saw a message (Toast?) flash briefly on the Gmail app, saying "Can't attach empty file". But it's not empty!!!
More New Information:
I tried using FileProvider to do this. Here's the code...
AndroidManifest.xml:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.myorg.myapp.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepaths" />
</provider>
filepaths.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="publicdocuments/" path="documents/" />
</paths>
MainActivity.java:
public void onClickSend(View v) {
Intent i = new Intent(android.content.Intent.ACTION_SEND);
String Email[] = { "my.address#gmail.com" };
i.putExtra(android.content.Intent.EXTRA_EMAIL, Email);
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Report");
i.setType("text/plain");
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
File f = new File(path, "file.csv");
Uri sUri = FileProvider.getUriForFile(MainActivity.this, "com.myorg.myapp.fileprovider", f);
i.setData(sUri);
i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(i);
}
The problem now is that it doesn't work - my app crashes again on the call to FileProvider.getUriForFile().
Here's the new LogCat:
--------- beginning of crash
07-29 13:45:27.116 10397-10397/com.myorg.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myorg.myapp, PID: 10397
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5612)
at android.view.View$PerformClick.run(View.java:22285)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
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)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5612)
at android.view.View$PerformClick.run(View.java:22285)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
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)
Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Documents/Tasks.csv
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
at com.myorg.myapp.MainActivity.onClickSend(MainActivity.java:214)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5612)
at android.view.View$PerformClick.run(View.java:22285)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
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)
As you can see, there is an InvocationTargetException, but I don't know why...
Additional Information: Replacing MainActivity.this with v.getContext() in FileProvider.getUriForFile() gives the same result.
So it seems really bizarre for my app to set up a FileProvider with access permissions for a public file
The app that you are trying to send it through may not have external storage access. Hence, FileProvider is still the recommended pattern.
This causes the app to crash with the message: "MyApp has stopped"
Use LogCat to examine the Java stack trace associated with the crash in whatever app "MyApp" is.
Also, please note that plain/text is not a valid MIME type. Presumably you mean text/plain.
And, given a File, use Uri.fromFile() to generate a Uri for it. Bear in mind that your app may crash on Android 7.0+ for using a file scheme, though, which is another reason for using FileProvider.
What is the right way to do this?
Use FileProvider.
My android app often goes not responding and then crashes printing the following log:
12-16 00:43:49.788 27523-27523/com.robocats.main W/linker: /data/app/com.google.android.webview-2/lib/arm64/libwebviewchromium.so: unused DT entry: type 0x6ffffffe arg 0x38c70
12-16 00:43:49.788 27523-27523/com.robocats.main W/linker: /data/app/com.google.android.webview-2/lib/arm64/libwebviewchromium.so: unused DT entry: type 0x6fffffff arg 0x3
12-16 00:43:49.908 27523-27523/com.robocats.main I/WebViewFactory: Loading com.google.android.webview version 55.0.2883.91 (code 288309150)
12-16 00:43:49.928 27523-27523/com.robocats.main I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
12-16 00:43:49.928 27523-27523/com.robocats.main I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
12-16 00:43:49.938 27523-27523/com.robocats.main I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
12-16 00:43:49.938 27523-27523/com.robocats.main I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
12-16 00:43:49.948 27523-27523/com.robocats.main I/cr_LibraryLoader: Time to load native libraries: 1 ms (timestamps 5331-5332)
12-16 00:43:49.948 27523-27523/com.robocats.main I/cr_LibraryLoader: Expected native library version number "55.0.2883.91", actual native library version number "55.0.2883.91"
12-16 00:43:49.958 27523-27523/com.robocats.main I/cr_LibraryLoader: Expected native library version number "55.0.2883.91", actual native library version number "55.0.2883.91"
12-16 00:43:49.978 27523-27523/com.robocats.main I/chromium: [INFO:library_loader_hooks.cc(163)] Chromium logging enabled: level = 0, default verbosity = 0
12-16 00:43:50.028 27523-27523/com.robocats.main I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
12-16 00:43:50.328 27523-27523/com.robocats.main D/CognitoCachingCredentialsProvider: Loading credentials from SharedPreferences
12-16 00:43:57.608 27523-27534/com.robocats.main I/art: Thread[7,tid=27534,WaitingInMainSignalCatcherLoop,Thread*=0x55982e3fc0,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
12-16 00:43:58.088 27523-27534/com.robocats.main I/art: Wrote stack traces to '/data/anr/traces.txt'
The logs are coming from webview, but I'm not at all using webview in my application. Any pointers here?
The intent of this is to have a webpage firing within the app itself. The app runs without glitches, but the webpage is never seen. The .xml contains the webpage and a list beneath it.
The .xml file reads as
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ListView
android:layout_width="fill_parent"
android:layout_height="500dp"
android:id="#android:id/list"/>
</LinearLayout>
The activity in the .java reads as
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView myWebView = new WebView(this);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("https://google.com");
// Other AWS gibberish
}
I can get the webpage to fire as an separate application, but this is not what I want.
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://google.ca");
Edit: I have already added the internet permission to the manifest
<uses-permission android:name="android.permission.INTERNET" />
Some references I have been using here, here, here and documentation without success
Edit 2: Going through the device debug files and the following are being logged
10-18 22:07:59.296 7717-7717/com.amazon.mysampleapp I/WebViewFactory: Loading com.google.android.webview version 53.0.2785.124 (code 278512400)
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: SBServiceAPI: getService class android.os.ServiceManager
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: isShipBuild true
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Thread-46729-141117018: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
10-18 22:07:59.336 7717-7826/com.amazon.mysampleapp I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
10-18 22:07:59.336 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
10-18 22:07:59.336 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
10-18 22:07:59.336 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
10-18 22:07:59.346 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
10-18 22:07:59.366 7717-7717/com.amazon.mysampleapp I/cr_LibraryLoader: Time to load native libraries: 6 ms (timestamps 655-661)
10-18 22:07:59.366 7717-7717/com.amazon.mysampleapp I/cr_LibraryLoader: Expected native library version number "53.0.2785.124", actual native library version number "53.0.2785.124"
10-18 22:07:59.376 7717-7717/com.amazon.mysampleapp W/ResourceType: Failure getting entry for 0x01080ad1 (t=7 e=2769) (error -75)
10-18 22:07:59.386 7717-7717/com.amazon.mysampleapp I/cr_LibraryLoader: Expected native library version number "53.0.2785.124", actual native library version number "53.0.2785.124"
10-18 22:07:59.396 7717-7717/com.amazon.mysampleapp I/chromium: [INFO:library_loader_hooks.cc(151)] Chromium logging enabled: level = 0, default verbosity = 0
10-18 22:07:59.436 7717-7717/com.amazon.mysampleapp I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
10-18 22:07:59.606 7717-7826/com.amazon.mysampleapp I/DefaultDeliveryClient: Successful submission of 4 events
10-18 22:07:59.646 7717-7843/com.amazon.mysampleapp W/cr_media: Requires BLUETOOTH permission
10-18 22:07:59.686 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$WebResourceErrorImpl>
10-18 22:07:59.696 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$WebResourceErrorImpl>
10-18 22:07:59.736 7717-7717/com.amazon.mysampleapp D/ConnectivityManager: CallingUid : 10097, CallingPid : 7717
10-18 22:07:59.736 7717-7854/com.amazon.mysampleapp D/ConnectivityManager.CallbackHandler: CM callback handler got msg 524290
10-18 22:07:59.766 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingWebActionModeCallback>
10-18 22:07:59.766 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingWebActionModeCallback>
Instead of instantiating a new Webview at onCreate I think you may need to use the one specified in your layout:
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.NAME_OF_THE_XML_FILE); // change here to match the name of your xml file
// WebView myWebView = new WebView(this); instead of this, try this one below:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("https://google.com");
// Other AWS gibberish
}
Hello everybody
I'm trying to show in a WebView a video from url, it is streaming and this is an example of the Url:
https://rapidresponse-us-oem-relay11.mios.com/relay/relay/relay/device/36050280/session/0144E086FE4180BB14CFA858AE7FE05757ED73/port_3480/data_request?id=serve_stream&cam=12&stream=29&res=low
I already did the IOS application and it works fine, so I know that the url don't have any problem.
I'm trying to show the video in the WebView with the following code:
if(message.getMessageType() == 0) {
webView_camera.getSettings().setDomStorageEnabled(true);
webView_camera.loadUrl(cameraUrl);
}
I tried to use this
webView_camera.setWebChromeClient(new WebChromeClient());
But it doesn't work either
When the application run only show int the webview the icon of failure to load an image.
I'm pretty new with this so any help will be appreciated it
UPDATE
This is the Logs that I get from android:
11-11 09:32:25.268 8316-8316/com.realstatediary.jperera.rapidsentrymaster I/WebViewFactory: Loading com.google.android.webview version 46.0.2490.76 (code 249007600)
11-11 09:32:25.294 8316-8316/com.realstatediary.jperera.rapidsentrymaster I/cr.library_loader: Time to load native libraries: 2 ms (timestamps 2963-2965)
11-11 09:32:25.294 8316-8316/com.realstatediary.jperera.rapidsentrymaster I/cr.library_loader: Expected native library version number "46.0.2490.76", actual native library version number "46.0.2490.76"
11-11 09:32:25.306 8316-8316/com.realstatediary.jperera.rapidsentrymaster V/WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper (main, tid 1) {b23e619}
11-11 09:32:25.307 8316-8316/com.realstatediary.jperera.rapidsentrymaster I/cr.library_loader: Expected native library version number "46.0.2490.76", actual native library version number "46.0.2490.76"
11-11 09:32:25.309 8316-8316/com.realstatediary.jperera.rapidsentrymaster I/chromium: [INFO:library_loader_hooks.cc(118)] Chromium logging enabled: level = 0, default verbosity = 0
11-11 09:32:25.329 8316-8316/com.realstatediary.jperera.rapidsentrymaster I/cr.BrowserStartup: Initializing chromium process, singleProcess=true
11-11 09:32:25.336 8316-8316/com.realstatediary.jperera.rapidsentrymaster E/SysUtils: ApplicationContext is null in ApplicationStatus
11-11 09:32:25.417 8316-8316/com.realstatediary.jperera.rapidsentrymaster E/chromium: [ERROR:browser_gpu_channel_host_factory.cc(258)] Failed to init browser shader disk cache.
11-11 09:32:25.445 8316-8316/com.realstatediary.jperera.rapidsentrymaster E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
11-11 09:32:25.449 8316-8774/com.realstatediary.jperera.rapidsentrymaster W/cr.media: Requires BLUETOOTH permission
11-11 09:32:25.471 8316-8316/com.realstatediary.jperera.rapidsentrymaster I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$WebResourceErrorImpl>
11-11 09:32:25.472 8316-8316/com.realstatediary.jperera.rapidsentrymaster I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$WebResourceErrorImpl>
11-11 09:32:25.526 8316-8316/com.realstatediary.jperera.rapidsentrymaster I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingWebActionModeCallback>
11-11 09:32:25.526 8316-8316/com.realstatediary.jperera.rapidsentrymaster I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingWebActionModeCallback>
11-11 09:32:25.554 8316-8316/com.realstatediary.jperera.rapidsentrymaster W/art: Attempt to remove local handle scope entry from IRT, ignoring
11-11 09:32:25.562 8316-8316/com.realstatediary.jperera.rapidsentrymaster W/AwContents: onDetachedFromWindow called when already detached. Ignoring
11-11 09:32:30.958 8316-8316/com.realstatediary.jperera.rapidsentrymaster W/cr.BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 8316
11-11 09:33:18.836 8316-8398/com.realstatediary.jperera.rapidsentrymaster D/PULLBACK: Executing background pull from server
I finally did!
This the solution:
if(message.getMessageType() == 0) {
StringBuilder html = new StringBuilder();
html.append("<html>");
html.append("<head>");
html.append("</head>");
html.append("<body>");
html.append("<div id ='main'><img class=\"video_player_frame\"src=\""+cameraUrl+" style=\"top: 0px; border: none; width: 100%; height: 100%;\"></div>");
html.append("</body>");
html.append("</html>");
webView_camera.loadData(html.toString(),"text/html", "UTF-8");
}