expo: Plugin with id ‘maven’ not found.

Summary

I Just upgraded react-native from 0.62.0 to 0.63.0 and all was working fine. But after I integrated expo unimodules in my bare expo project when I try to make the build for android then expo dependencies give me the below error.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

No response

Environment

React-native : 0.63.0 Expo Unimodules : 0.13.3 Gradle version : 7.0 Project : Typescript

buildToolsVersion = “30.0.0” minSdkVersion = 21 compileSdkVersion = 30 targetSdkVersion = 30

Reproducible demo or steps to reproduce from a blank project

  • Integrate it for the bare project after upgrading to 0.63.0 from 0.62.0 .

Error

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0/userguide/command_line_interface.html#sec:command_line_warnings

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/Users/ios/Desktop/Old MacMini Data/Desktop/React Live Projects/afridom/node_modules/expo-constants/android/build.gradle' line: 2

* What went wrong:
A problem occurred evaluating project ':expo-constants'.
> Plugin with id 'maven' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':expo-constants'.
> compileSdkVersion is not specified. Please add it to build.gradle

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 12s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 22
  • Comments: 33 (12 by maintainers)

Commits related to this issue

Most upvoted comments

android studio 4.2 with gradle 7.0.1 gives below error

> Plugin with id 'maven' not found.

downgraded gradle-6.8.1-all.zip in gradle-wrapper.properties … working good

Temporary workaround:

For any expo package, go to its android/build.gradle and modify to use maven-publish plugin:

 apply plugin: 'com.android.library'
 apply plugin: 'kotlin-android'
-apply plugin: 'maven'
+apply plugin: 'maven-publish'
 
 group = 'host.exp.exponent'
 version = '9.2.2'
 buildscript {
   }
 }
 
-// Upload android library to maven with javadoc and android sources
-configurations {
-  deployerJars
-}
-
 // Creating sources with comments
 task androidSourcesJar(type: Jar) {
-  classifier = 'sources'
+  archiveClassifier = '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)
+publishing {
+  publications {
+    maven(MavenPublication) {
+      artifact androidSourcesJar
     }
   }
 }

I stumbled here via google search and just wanted to let you guys know that the ‘maven’ plugin was deprecated in gradle 7. The suggested replacement is maven-publish. I belive the previous plugin had a bit different purpose. I could be wrong, though.

For those using gradle 7, maven plugin has been removed, now you should use maven-publish, as described in official site at this link: https://docs.gradle.org/7.0/userguide/upgrading_version_6.html?_ga=2.21245883.1883799052.1624281891-1948725710.1624281891#removal_of_the_legacy_maven_plugin So, instead of using: apply plugin: 'maven' you should use apply plugin: 'maven-publish'

To summarise for those running into this issue:

Change gradle build tools in the main build.gralde to: classpath 'com.android.tools.build:gradle:4.2.2'

Change distribution url in the yourproject/gradle/wrapper/gradle-wrapper.properties file to: distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip

The jump between the 7.0 version and the versions mentioned above is so huge because they are aligning the version numbers with the Gradle version number. The versions mentioned above just before the 7.0 versions.

Hi @brentvatne thanks for your suggestion. à The problem actually was with the Gradle version. I just had to downgrade my Gradle version to version 6.4.1 using sdk-manager while following this guide

then, gradle wrapper command worked

To summarise for those running into this issue:

Change gradle build tools in the main build.gralde to: classpath 'com.android.tools.build:gradle:4.2.2'

Change distribution url in the yourproject/gradle/wrapper/gradle-wrapper.properties file to: distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip

The jump between the 7.0 version and the versions mentioned above is so huge because they are aligning the version numbers with the Gradle version number. The versions mentioned above just before the 7.0 versions.

This results in a number of No signature of method errors for certain react native packages.

No signature of method: build_1pnz21phoowefc22xejnoeuib.android() is applicable for argument types: (build_1pnz21phoowefc22xejnoeuib$_run_closure1) values: [build_1pnz21phoowefc22xejnoeuib$_run_closure1@23db40cd]

Anyone facing this?

+1 for gradle 7 support

What’s the plan for supporting Gradle 7? Now that React Native supports it.

Android Studio Artic Fox is promoting to upgrade to Gradle 7+. Almost everyone who is using the bare workflow with the latest Android Studio will get this issue. Mirgating to “maven-publish” will save a lot of hassle for developers who haven’t had this issue yet. Is this migration very complex?

For anyone who wants this temporary fix (please read the code yourself), I made a quick fix file with the examples here and from the replace-in-files node module. I realize that it is sloppy, but it should get everything for an upgrade. I had missed the publications part in my initial run, so I haven’t tested it with that.

const replaceInFiles = require('replace-in-files')

const options = {
  // See more: https://www.npmjs.com/package/globby
  // Single file or glob
  files: 'path/to/file',
  // Multiple files or globs
  files: ['**/node_modules/**/build.gradle'],
  optionsForFiles: {
    // default
    ignore: []
  },
  // See more: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
  // Replacement
  from: `apply plugin: 'maven'`, // string or regex
  to: `apply plugin: 'maven-publish'` // string or fn  (fn: carrying last argument - path to replaced file)
}

replaceInFiles(options)
  .then(({ changedFiles, countOfMatchesByPaths }) => {
    console.log('Modified files:', changedFiles)
    console.log('Count of matches by paths:', countOfMatchesByPaths)
    console.log('was called with:', options)

    options.from = /configurations\s*{\s*deployerJars\s*}/gm
    options.to = ``

    replaceInFiles(options)
      .then(({ changedFiles, countOfMatchesByPaths }) => {
        console.log('Modified files:', changedFiles)
        console.log('Count of matches by paths:', countOfMatchesByPaths)
        console.log('was called with:', options)

        options.from = `classifier = 'sources'`
        options.to = `archiveClassifier = 'sources'`

        replaceInFiles(options)
          .then(({ changedFiles, countOfMatchesByPaths }) => {
            console.log('Modified files:', changedFiles)
            console.log('Count of matches by paths:', countOfMatchesByPaths)
            console.log('was called with:', options)

            options.from = /artifacts\s*{\s*archives androidSourcesJar\s*}/gm
            options.to = ``

            replaceInFiles(options)
              .then(({ changedFiles, countOfMatchesByPaths }) => {
                console.log('Modified files:', changedFiles)
                console.log('Count of matches by paths:', countOfMatchesByPaths)
                console.log('was called with:', options)

                options.from = /uploadArchives\s*{\s*repositories\s*{\s*mavenDeployer\s*{\s*configuration\s*=\s*configurations.deployerJars\s*repository\(url:\s*mavenLocal\(\).url\)/gm
                options.to = `publishing {
                  publications {
                    maven(MavenPublication) {
                      artifact androidSourcesJar`
                replaceInFiles(options)
                  .then(({ changedFiles, countOfMatchesByPaths }) => {
                    console.log('Modified files:', changedFiles)
                    console.log(
                      'Count of matches by paths:',
                      countOfMatchesByPaths
                    )
                    console.log('was called with:', options)
                    console.log('finished')
                  })
                  .catch(error => {
                    console.error('Error occurred:', error)
                  })
              })
              .catch(error => {
                console.error('Error occurred:', error)
              })
          })
          .catch(error => {
            console.error('Error occurred:', error)
          })
      })
      .catch(error => {
        console.error('Error occurred:', error)
      })
  })
  .catch(error => {
    console.error('Error occurred:', error)
  })

Hi @brentvatne thanks for your suggestion. à The problem actually was with the Gradle version. I just had to downgrade my Gradle version to version 6.4.1 using sdk-manager while following this guide

then, gradle wrapper command worked

After installing gradle6.4.1 using sdk manager and setting gradle wrapper

Good - I think that’s the only way to go for the moment

I have used your method. I have used sdk manager and downgrade my gradle to 6.4.1 but my android studio artic fox supports only gradle 7.0 and my react-native modules do not support gradle 7.0. I am using macbook pro m1 chip. The error which i am getting is this:

Minimum supported Gradle version is 7.0.2. Current version is 6.4.1.

Please help me out on the same.

Good - I think that’s the only way to go for the moment