如何从maven迁移到maven-publish

Olg*_*ova 8 android gradle maven android-studio

我正在尝试使用 Android Studio 为 Google Play 制作 Android 应用程序包。Android Studio 告诉我需要为此升级 Gradle。我将 Gradle 迁移到 7.0.0 版本(并更新了 Android Studio 本身),但我对此完全陌生,所以现在我遇到了 Maven 问题。我收到以下错误:

构建文件“/Users/administrator/noughts-and-crosses/node_modules/expo-application/android/build.gradle”行:2

评估项目“:expo-application”时出现问题。

未找到 ID 为“maven”的插件。

我发现maven已经不用了,所以需要迁移到maven-publish。我将maven更改为maven-publish,但现在我遇到以下问题:

构建文件“/Users/administrator/noughts-and-crosses/node_modules/expo-application/android/build.gradle”行:28

评估项目“:expo-application”时出现问题。

在 org.gradle.api.Project 类型的项目“:expo-application”上找不到参数 [build_6lgwxdh9lx7r2mkhkk2he2s1g$_run_closure4@56af98de] 的方法 uploadArchives()。

存在问题的 build.gradle 文件如下所示:

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

group = 'host.exp.exponent'
version = '3.1.2'

// Simple helper that allows the root project to override versions declared by this library.
def safeExtGet(prop, fallback) {
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

// Upload android library to maven with javadoc and android sources
configurations {
  deployerJars
}

// Creating sources with comments
task androidSourcesJar(type: Jar) {
  classifier = 'sources'
  from android.sourceSets.main.java.srcDirs
}

// Put the androidSources and javadoc to the artifacts
artifacts {
  archives androidSourcesJar
}

uploadArchives {
  repositories {
    mavenDeployer {
      configuration = configurations.deployerJars
      repository(url: mavenLocal().url)
    }
  }
}

android {
  compileSdkVersion safeExtGet("compileSdkVersion", 30)

  defaultConfig {
    minSdkVersion safeExtGet("minSdkVersion", 21)
    targetSdkVersion safeExtGet("targetSdkVersion", 30)
    versionCode 12
    versionName '3.1.2'
  }
  lintOptions {
    abortOnError false
  }
}

if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
  apply from: project(":unimodules-core").file("../unimodules-core.gradle")
} else {
  throw new GradleException(
      '\'unimodules-core.gradle\' was not found in the usual React Native dependency location. ' +
          'This package can only be used in such projects. Are you sure you\'ve installed the dependencies properly?')
}

dependencies {
  unimodule 'unimodules-core'
  implementation 'com.android.installreferrer:installreferrer:1.0'
}
Run Code Online (Sandbox Code Playgroud)

那么,问题是:如何解决新问题?

更新。我从评论中阅读了这篇文章,现在文件如下所示:

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

// Simple helper that allows the root project to override versions declared by this library.
def safeExtGet(prop, fallback) {
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

// Upload android library to maven with javadoc and android sources
configurations {
  deployerJars
}

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release

                groupId = 'host.exp.exponent'
                artifactId = 'noughts-and-crosses'
                version = '3.1.2'
                artifact(sourcesJar)
            }
        }
    }
}

uploadArchives {
  repositories {
    mavenDeployer {
      configuration = configurations.deployerJars
      repository(url: mavenLocal().url)
    }
  }
}

android {
  compileSdkVersion safeExtGet("compileSdkVersion", 30)

  defaultConfig {
    minSdkVersion safeExtGet("minSdkVersion", 21)
    targetSdkVersion safeExtGet("targetSdkVersion", 30)
    versionCode 12
    versionName '3.1.2'
  }
  lintOptions {
    abortOnError false
  }
}

if (new File(rootProject.projectDir.parentFile, 'package.json').exists()) {
  apply from: project(":unimodules-core").file("../unimodules-core.gradle")
} else {
  throw new GradleException(
      '\'unimodules-core.gradle\' was not found in the usual React Native dependency location. ' +
          'This package can only be used in such projects. Are you sure you\'ve installed the dependencies properly?')
}

dependencies {
  unimodule 'unimodules-core'
  implementation 'com.android.installreferrer:installreferrer:1.0'
}
Run Code Online (Sandbox Code Playgroud)

但这并没有解决问题。