`ns run android` 上的 NativeScript 重复 kotlin 类

问题描述 投票:0回答:1

我一直在开发一个应用程序,这是我从一位即将离职的同事那里得到的,而且我是 NativeScript 的新手。

尝试使用

ns run android
命令在 Android 模拟器上运行应用程序时,出现以下错误:

Execution failed for task ':app:checkDebugDuplicateClasses'.
Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
Duplicate class kotlin.jvm.jdk8.JvmRepeatableKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
Duplicate class kotlin.random.jdk8.PlatformThreadLocalRandom found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
Duplicate class kotlin.streams.jdk8.StreamsKt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$1 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$2 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$3 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$4 found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
Duplicate class kotlin.text.jdk8.RegexExtensionsJDK8Kt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)
Duplicate class kotlin.time.jdk8.DurationConversionsJDK8Kt found in modules jetified-kotlin-stdlib-1.9.0 (org.jetbrains.kotlin:kotlin-stdlib:1.9.0) and jetified-kotlin-stdlib-jdk8-1.6.0 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0)

Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.

我尝试过以下方法:

  • 更新 NativeScript
  • 更新所有依赖项
  • 检查较旧的提交,确保这不是由于我上次提交造成的
  • 在不同的机器(MacO 和 Ubuntu)上尝试此操作
  • 按照有关此问题的其他帖子向
    platforms/android/build.gradle
    文件添加不同的代码行...

ns run ios
工作正常,所以我猜这与 Java/Android 相关。任何帮助将不胜感激。

我的

package.json
文件如果这可以帮助:

{
  "description": "NativeScript Application",
  "main": "app/app.js",
  "license": "SEE LICENSE IN <your-license-filename>",
  "repository": "<fill-your-repository-here>",
  "version": "7.0.1",
  "publishConfig": {
    "access": "public"
  },
  "dependencies": {
    "@finanzritter/nativescript-share-file": "^2.0.1",
    "@nativescript-community/sentry": "^4.6.12",
    "@nativescript-community/ui-canvas": "^4.0.50",
    "@nativescript-community/ui-collectionview": "^4.0.29",
    "@nativescript-community/ui-image": "4.3.6",
    "@nativescript-community/ui-material-bottom-navigation": "^7.0.24",
    "@nativescript-community/ui-material-core": "^7.0.24",
    "@nativescript-community/ui-material-tabs": "^7.0.24",
    "@nativescript-community/ui-pager": "^13.0.2",
    "@nativescript-community/ui-pulltorefresh": "^2.5.3",
    "@nativescript-community/ui-webview": "^1.4.4",
    "@nativescript-community/universal-links": "^2.0.7",
    "@nativescript/background-http": "^6.0.0",
    "@nativescript/camera": "^5.0.15",
    "@nativescript/core": "~8.5.9",
    "@nativescript/email": "^2.0.5",
    "@nativescript/firebase-analytics": "^3.1.0",
    "@nativescript/firebase-core": "^3.1.0",
    "@nativescript/firebase-messaging": "^3.1.0",
    "@nativescript/geolocation": "^8.1.0",
    "@nativescript/imagepicker": "^1.0.9",
    "@nativescript/localize": "^5.0.2",
    "@nativescript/social-share": "^2.0.1",
    "@nativescript/theme": "~3.0.2",
    "buffer": "^6.0.3",
    "moment": "^2.29.0",
    "nativescript-barcodescanner": "^4.1.2",
    "nativescript-imagecropper": "^4.0.1",
    "nativescript-phone": "^2.0.0",
    "nativescript-plugin-universal-links": "^2.0.0",
    "nativescript-ui-calendar": "^7.0.2",
    "nativescript-ui-chart": "^8.0.2",
    "nativescript-ui-listview": "^9.1.0",
    "nativescript-vue": "~2.9.3",
    "nativescript-vue-multi-drawer": "^0.0.4",
    "nativescript-websockets": "^1.5.6",
    "vue": "^2.6.12",
    "vue-template-compiler": "^2.6.12",
    "vuelidate": "^0.7.6",
    "vuex": "^3.5.1"
  },
  "devDependencies": {
    "@nativescript/android": "8.6.2",
    "@nativescript/ios": "~8.6.1",
    "@nativescript/webpack": "~5.0.18",
    "nativescript-vue-template-compiler": "~2.9.3"
  },
  "gitHead": "-",
  "readme": "NativeScript Application"
}

[更新2024-02-01] 与此同时,我已经能够将罪魁祸首减少到 2 个依赖项:

  • “@nativescript/geolocation”:“^8.3.1”
  • “@nativescript/background-http”:“^6.0.0”,
android kotlin gradle nativescript nativescript-vue
1个回答
0
投票

发现 Ionic 和 React Native 存在类似问题,并尝试对我的 NativeScript 项目应用相同的修复。看起来好像有效了。我不确定这个解决方案有多好和面向未来,我很感激其他人的评论,但它让我克服了困难。 将其添加到您的 app.gradle 文件中:

dependencies {
  constraints {
      implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
          because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
      }
      implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
          because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
      }
  }
}

希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.