couchbase / couchbase-lite-android-ce

The community edition of couchbase lite for android
Apache License 2.0
9 stars 1 forks source link

Crash importing 2.6.0 in a new Android Studio project #28

Closed dariopellegrini closed 4 years ago

dariopellegrini commented 4 years ago

Hello. I'm experiencing a crash while adding Couchbase 2.6.0 through Gradle on a new Android Studio 3.5 project.

The crash says java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mypackage.myapplication/com.mypackage.myapplication.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.mypackage.myapplication.MainActivity" on path: DexPathList[[zip file "/data/app/com.mypackage.myapplication-eEQxhjvy2kuLuIPqVZPIkA==/base.apk"],nativeLibraryDirectories=[/data/app/com.mypackage.myapplication-eEQxhjvy2kuLuIPqVZPIkA==/lib/arm64, /data/app/com.mypackage.myapplication-eEQxhjvy2kuLuIPqVZPIkA==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]

Here are the Gradle file and the Manifest file generated by Android Studio 3.5.

Gradle file with Couchbase import in addiction

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.mypackage.myapplication"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'com.couchbase.lite:couchbase-lite-android:2.6.0'
}

Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mypackage.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Just changing Couchbase 2.6.0 to 2.5.2 version in Gradle file solves the issue.

I know that it seems an application issue, but it appears only when there is a CouchbaseLite 2.6.0 dependency and from a new Android Studio project.

Any idea why is happening? Maybe a Couchbase issue or a misconfiguration of my project?

bmeike commented 4 years ago

I agree that this seems like an application issue. That error message says that you don't have a class called com.mypackage.myapplication.MainActivity in your application. Do you?

CBL has a native component and it is possible that AS 3.5 is doing something funny with that.

Could you try 2.6.0 with an older version of AS, and report back

dariopellegrini commented 4 years ago

@bmeike The class exists and with 2.5.2 the app works properly. The problem starts with 2.6.0.

I've tried with an older project generated by AS 3.4 on AS 3.5 and with 2.6 it works.

It seems that the problem is with project generated with AS 3.5 not with AS 3.5 itself. I'm investigating this issue and I'll let you know further details.

Any help is welcome :) Can you reproduce the issue?

dariopellegrini commented 4 years ago

@bmeike ok I have it and it seems a problem with Couchbase 2.6.0, but I don't know if it is from me or from CouchbaseLite.

I've ran ./gradlew assemble clean and the process fails. Here are the reasons:

> Task :app:stripDebugDebugSymbols
Compatible side by side NDK version was not found.
Unable to strip library '/Users/dariopellegrini/Documents/Android/MyApplication3/app/build/intermediates/merged_native_libs/debug/out/lib/arm64-v8a/libLiteCoreJNI.so' due to missing strip tool for ABI 'ARM64_V8A'. Packaging it as is.
Unable to strip library '/Users/dariopellegrini/Documents/Android/MyApplication3/app/build/intermediates/merged_native_libs/debug/out/lib/x86_64/libLiteCoreJNI.so' due to missing strip tool for ABI 'X86_64'. Packaging it as is.

> Transform artifact couchbase-lite-android.aar (com.couchbase.lite:couchbase-lite-android:2.6.0) with DexingNoClasspathTransform
AGPBI: {"kind":"error","text":"Invoke-customs are only supported starting with Android O (--min-api 26)","sources":[{}],"tool":"D8"}

> Task :app:stripReleaseDebugSymbols
Unable to strip library '/Users/dariopellegrini/Documents/Android/MyApplication3/app/build/intermediates/merged_native_libs/release/out/lib/armeabi-v7a/libLiteCoreJNI.so' due to missing strip tool for ABI 'ARMEABI_V7A'. Packaging it as is.
Unable to strip library '/Users/dariopellegrini/Documents/Android/MyApplication3/app/build/intermediates/merged_native_libs/release/out/lib/x86/libLiteCoreJNI.so' due to missing strip tool for ABI 'X86'. Packaging it as is.
Unable to strip library '/Users/dariopellegrini/Documents/Android/MyApplication3/app/build/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libLiteCoreJNI.so' due to missing strip tool for ABI 'ARM64_V8A'. Packaging it as is.
Unable to strip library '/Users/dariopellegrini/Documents/Android/MyApplication3/app/build/intermediates/merged_native_libs/release/out/lib/x86_64/libLiteCoreJNI.so' due to missing strip tool for ABI 'X86_64'. Packaging it as is.

> Task :app:mergeExtDexDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform artifact 'couchbase-lite-android.aar (com.couchbase.lite:couchbase-lite-android:2.6.0)' to match attributes {artifactType=android-dex, dexing-enable-desugaring=false, dexing-is-debuggable=true, dexing-min-sdk=24}.
      > Execution failed for DexingNoClasspathTransform: /Users/dariopellegrini/.gradle/caches/transforms-2/files-2.1/981d2748c0e403ed9c2eea757b576975/jetified-couchbase-lite-android-2.6.0/jars/classes.jar.
         > Error while dexing.
           The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle
           android {
               compileOptions {
                   sourceCompatibility 1.8
                   targetCompatibility 1.8
               }
           }
           See https://developer.android.com/studio/write/java8-support.html for details. Alternatively, increase the minSdkVersion to 26 or above.

The workaround is to add

compileOptions {
                   sourceCompatibility 1.8
                   targetCompatibility 1.8
               }

It seems to work. Maybe there is an issue in new Couchbase 2.6.0 compilation, I don't know, but I hope the above log helps you to find out what was happening.

bmeike commented 4 years ago

Work around??? That isn't a workaround! That is a documented dependency! Sorry I didn't notice its absence in your original post. Glad it is working, now.