android 添加依赖后Kotlin版本不兼容(元数据为1.6.0,预期版本为1.4.0)

xqkwcwgp  于 2023-04-18  发布在  Android
关注(0)|答案(1)|浏览(316)

bounty已结束,回答此问题可获得+100声望奖励,奖励宽限期18小时后结束,snachmsm希望引起更多关注此问题。

我的项目包含三个模块:main - pure Java,3rd-party app - pure Java and another 3rd-party app -Kotlin,1.5.10
项目没有维护,但仍然工作,我有一个任务,以实现一些库在它,在主模块.我已经开发了整个解决方案,没有调试问题,但现在当我试图构建发布APK我得到4在:lintVitalBasicRelease阶段类似于下面的错误

..f4b73468ce598bb17f04/kotlin-stdlib-1.6.0.jar!/META-INF/kotlin-stdlib.kotlin_module:
Module was compiled with an incompatible version of Kotlin.
The binary version of its metadata is 1.6.0, expected version is 1.4.0.

kotlin-stdlib-common-1.6.0.jarpreference-1.2.0.jarslidingpanelayout-1.2.0.jar相同,所有版本均为1.6/1.4
项目等级:

buildscript {
    ext.kotlin_version = '1.5.10'
    repositories {
        jcenter()
        flatDir {
            dirs 'libs'
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        ...

第三方Kotlin应用/模块的gradle:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        
        ...
        
dependencies {
    compile "androidx.core:core-ktx:1.6.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    ...

main module(noKotlin!):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 31
    buildToolsVersion '30.0.3'

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 27
        
        ...
        
dependencies {
    ...
    implementation('com.dji:dji-sdk:4.16.4', {
        exclude module: 'fly-safe-database'
    })
    compileOnly 'com.dji:dji-sdk-provided:4.16.4'
    ...
    implementation project(path: ':somekotlininhere')
    implementation project(path: ':purejavamodule')
}

没有张贴以上实施THIS SDK项目正在建设和签署罚款,我生产APK没有问题
有趣的是,在链接的sdk repo中,我们可以找到Sample Code,它们具有完全相同的Kotlin版本(1.5.10)和依赖项,甚至以相同的方式声明(使用共享的ext.kotlin_version
更新Kotlin到最新的1.8.10引入了一些新的错误/弃用,解决后我回到了相同的点和初始错误......我已经恢复了这个更改,我不是Kotlin模块的作者,我宁愿不碰
所以:什么是适当的声明,我的情况下,我如何才能释放我的项目现在,因为它的工作相当不错“通过电缆”(调试)
是的,这个问题是THIS的重复,但我相信我已经发布了更多有用和详细的信息来解决这个问题。

x6yk4ghg

x6yk4ghg1#

也许将以下代码行放入项目的Gradle中对您有用

afterEvaluate {

    tasks.withType<KotlinCompile>().configureEach {
        kotlinOptions {
            apiVersion = "1.5"
            languageVersion = "1.5"
        }
    }
}

或者你只需要关掉你的线头警告

android {
    lintOptions {
        checkReleaseBuilds false
        //If you want to continue even if errors found use following line
        abortOnError false
    }
}

但我不推荐那些。
最困难的方法是升级依赖项,但它更可靠。

// use this dependency if your java target is 1.8 or above
org.jetbrains.kotlin:kotlin-stdlib:

在您的应用程序Gradle中,根据您的Java版本使用以下代码

android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
}

经编辑的答案_________________________________________
在您的app Gradle中尝试以下打包选项:

android {
    ...
    
    defaultConfig {
        ...
        
        ndk {
            // On x86 devices that run Android API 23 or above, if the application is targeted with API 23 or
        // above, FFmpeg lib might lead to runtime crashes or warnings.
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
    }

    packagingOptions {
        doNotStrip "*/*/libdjivideo.so"
        doNotStrip "*/*/libSDKRelativeJNI.so"
        doNotStrip "*/*/libFlyForbid.so"
        doNotStrip "*/*/libduml_vision_bokeh.so"
        doNotStrip "*/*/libyuv2.so"
        doNotStrip "*/*/libGroudStation.so"
        doNotStrip "*/*/libFRCorkscrew.so"
        doNotStrip "*/*/libUpgradeVerify.so"
        doNotStrip "*/*/libFR.so"
        doNotStrip "*/*/libDJIFlySafeCore.so"
        doNotStrip "*/*/libdjifs_jni.so"
        doNotStrip "*/*/libsfjni.so"
        doNotStrip "*/*/libDJICommonJNI.so"
        doNotStrip "*/*/libDJICSDKCommon.so"
        doNotStrip "*/*/libDJIUpgradeCore.so"
        doNotStrip "*/*/libDJIUpgradeJNI.so"
        doNotStrip "*/*/libDJIWaypointV2Core.so"
        doNotStrip "*/*/libAMapSDK_MAP_v6_9_2.so"
        doNotStrip "*/*/libDJIMOP.so"
        doNotStrip "*/*/libDJISDKLOGJNI.so"
        exclude 'META-INF/rxjava.properties'
        exclude 'assets/location_map_gps_locked.png'
        exclude 'assets/location_map_gps_3d.png'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

app progaurd file中的progaurd规则:

-keepattributes Exceptions,InnerClasses,*Annotation*,Signature,EnclosingMethod

-dontoptimize
-dontpreverify
-dontwarn okio.**
-dontwarn org.bouncycastle.**
-dontwarn dji.**
-dontwarn com.dji.**
-dontwarn sun.**
-dontwarn java.**
-dontwarn com.amap.api.**
-dontwarn com.here.**
-dontwarn com.mapbox.**
-dontwarn okhttp3.**
-dontwarn retrofit2.**

-keepclassmembers enum * {
    public static <methods>;
}

-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}
-keep class * extends android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}

-keep,allowshrinking class * extends dji.publics.DJIUI.** {
    public <methods>;
}

-keep class net.sqlcipher.** { *; }

-keep class net.sqlcipher.database.* { *; }

-keep class dji.** { *; }

-keep class com.dji.** { *; }

-keep class com.google.** { *; }

-keep class org.bouncycastle.** { *; }

-keep,allowshrinking class org.** { *; }

-keep class com.squareup.wire.** { *; }

-keep class sun.misc.Unsafe { *; }

-keep class com.secneo.** { *; }

-keep class org.greenrobot.eventbus.**{*;}

-keep class it.sauronsoftware.ftp4j.**{*;}

-keepclasseswithmembers,allowshrinking class * {
    native <methods>;
}

-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

-keep class androidx.appcompat.widget.SearchView { *; }

-keepclassmembers class * extends android.app.Service
-keepclassmembers public class * extends android.view.View {
    void set*(***);
    *** get*();
}
-keepclassmembers class * extends android.app.Activity {
    public void *(android.view.View);
}
-keep class androidx.** { *; }
-keep class android.media.** { *; }
-keep class okio.** { *; }
-keep class com.lmax.disruptor.** { *; }
-keep class com.qx.wz.dj.rtcm.* { *; }

-dontwarn com.mapbox.services.android.location.LostLocationEngine
-dontwarn com.mapbox.services.android.location.MockLocationEngine
-keepclassmembers class * implements android.arch.lifecycle.LifecycleObserver {
    <init>(...);
}
# ViewModel's empty constructor is considered to be unused by proguard
-keepclassmembers class * extends android.arch.lifecycle.ViewModel {
    <init>(...);
}
# keep Lifecycle State and Event enums values
-keepclassmembers class android.arch.lifecycle.Lifecycle$State { *; }
-keepclassmembers class android.arch.lifecycle.Lifecycle$Event { *; }
# keep methods annotated with @OnLifecycleEvent even if they seem to be unused
# (Mostly for LiveData.LifecycleBoundObserver.onStateChange(), but who knows)
-keepclassmembers class * {
    @android.arch.lifecycle.OnLifecycleEvent *;
}

-keepclassmembers class * implements android.arch.lifecycle.LifecycleObserver {
    <init>(...);
}

-keep class * implements android.arch.lifecycle.LifecycleObserver {
    <init>(...);
}
-keepclassmembers class android.arch.** { *; }
-keep class android.arch.** { *; }
-dontwarn android.arch.**

-keep class org.apache.commons.** {*;}

#<------------ utmiss config start------------>
-keep class dji.sdk.utmiss.** { *; }
-keep class utmisslib.** { *; }
#<------------ utmiss config end------------>

希望这能推动你前进:)

相关问题