[BUG] Android Studio Project crashes after adding library dependency
See original GitHub issueHi! Im trying to use the library in an Android project. As suggested here https://github.com/skrapeit/skrape.it/issues/89 I added this to my build.gradle to avoid having problems with the methods containing space in its names and so.
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
testImplementation("com.github.skrapeit:skrape.it:master-SNAPSHOT")
}
And I was able to run this Unit Test successfully
import it.skrape.core.htmlDocument
import it.skrape.matchers.toBe
import it.skrape.matchers.toContain
import it.skrape.selects.html5.h1
import it.skrape.selects.html5.p
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
internal fun `can read and return html from String`() {
htmlDocument(
"""
<html>
<body>
<h1>welcome</h1>
<div>
<p>first p-element</p>
<p class="foo">some p-element</p>
<p class="foo">last p-element</p>
</div>
</body>
</html>"""
) {
h1 {
findFirst {
text toBe "welcome"
}
}
p {
withClass = "foo"
findFirst {
text toBe "some p-element"
className toBe "foo"
}
}
p {
findAll {
this@htmlDocument.text toContain "p-element"
}
findLast {
text toBe "last p-element"
}
}
}
}
}
No problem so far, I guess because the Unit Tests run inside JVM.
After that I tried to add the dependency to use it from my Android Project adding this to my build.gradle
implementation("com.github.skrapeit:skrape.it:master-SNAPSHOT")
And received this error:
More than one file was found with OS independent path ‘META-INF/DEPENDENCIES’
After a little google search I found this to be the possible solution, so I added this to my build.gradle
android {
packagingOptions {
pickFirst "META-INF/DEPENDENCIES"
}
}
After adding that Im gettin more errors, so I think this might not be the solution Here is the StackTrace when I try to run the app
2020-05-19 01:26:30.841 14644-14644/? I/webscrappertes: Late-enabling -Xcheck:jni
2020-05-19 01:26:30.879 14644-14644/? E/webscrappertes: Unknown bits set in runtime_flags: 0x8000
2020-05-19 01:26:31.299 14644-14644/? W/webscrappertes: Bad encoded_array value: Failure to verify dex file '/data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/base.apk': Bad encoded_value method type size 7
2020-05-19 01:26:31.306 14644-14644/? E/LoadedApk: Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/base.apk"],nativeLibraryDirectories=[/data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/lib/arm64, /system/lib64, /vendor/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.LoadedApk.createAppFactory(LoadedApk.java:256)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:855)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:950)
at android.app.LoadedApk.getResources(LoadedApk.java:1188)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2462)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2454)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6353)
at android.app.ActivityThread.access$1300(ActivityThread.java:220)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Suppressed: java.io.IOException: Failed to open dex files from /data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/base.apk because: Bad encoded_array value: Failure to verify dex file '/data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/base.apk': Bad encoded_value method type size 7
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:365)
at dalvik.system.DexFile.<init>(DexFile.java:107)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:444)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:403)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:126)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:101)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:851)
... 13 more
2020-05-19 01:26:31.330 14644-14644/? I/Perf: Connecting to perf service.
2020-05-19 01:26:31.342 14644-14679/? E/Perf: Fail to get file list cu.neosoft.webscrappertest
2020-05-19 01:26:31.342 14644-14679/? E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-05-19 01:26:31.342 14644-14679/? E/Perf: Fail to get file list cu.neosoft.webscrappertest
2020-05-19 01:26:31.343 14644-14679/? E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-05-19 01:26:31.396 14644-14644/? D/AndroidRuntime: Shutting down VM
--------- beginning of crash
2020-05-19 01:26:31.400 14644-14644/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: cu.neosoft.webscrappertest, PID: 14644
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{cu.neosoft.webscrappertest/cu.neosoft.webscrappertest.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "cu.neosoft.webscrappertest.MainActivity" on path: DexPathList[[zip file "/data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/base.apk"],nativeLibraryDirectories=[/data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/lib/arm64, /system/lib64, /vendor/lib64, /system/product/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: java.lang.ClassNotFoundException: Didn't find class "cu.neosoft.webscrappertest.MainActivity" on path: DexPathList[[zip file "/data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/base.apk"],nativeLibraryDirectories=[/data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/lib/arm64, /system/lib64, /vendor/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at android.app.Instrumentation.newActivity(Instrumentation.java:1251)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3183)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Suppressed: java.io.IOException: Failed to open dex files from /data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/base.apk because: Bad encoded_array value: Failure to verify dex file '/data/app/cu.neosoft.webscrappertest-hy3VhMUfmFw2eV1pLwg5LQ==/base.apk': Bad encoded_value method type size 7
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:365)
at dalvik.system.DexFile.<init>(DexFile.java:107)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:444)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:403)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:126)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:101)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:851)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:950)
at android.app.LoadedApk.getResources(LoadedApk.java:1188)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2462)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2454)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6353)
2020-05-19 01:26:31.400 14644-14644/? E/AndroidRuntime: at android.app.ActivityThread.access$1300(ActivityThread.java:220)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
... 6 more
If there is any need for more info I’ll be happy to provide it. Thanks in advance !
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (1 by maintainers)
Thx to @faogustavo and we have a working android example over here: https://github.com/skrapeit/skrape-android-sample
Unfortunately I still get an error here:
I thought it could be some dependency, and it is actually the skrape{it} library. This is the output when running
./gradlew app:dependencies
:You can see that jetty is a dependency of skrape{it}.
Thanks!