问题
I am currently attempting to emulate (and then build) and Ionic App (w/ Angular) for Android. I feel the need to preface this by saying am not an Android developer, this is the first time I've had to set up the environment so I apologize for any "obvious" mistakes or missed steps.
I have been unable to get past this error (appears after running ionic cordova emulate android --debug --consolelogs
):
BUILD FAILED
Total time: 0.794 secs
[11:12:25] lint finished in 1.74 s
Error: /path/to/app/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/app/platforms/android/build.gradle' line: 24
* What went wrong:
A problem occurred evaluating root project 'android'.
> Could not find which method maven() to invoke from this list:
public abstract org.gradle.api.artifacts.repositories.MavenArtifactRepository org.gradle.api.artifacts.dsl.RepositoryHandler#maven(groovy.lang.Closure)
public abstract org.gradle.api.artifacts.repositories.MavenArtifactRepository org.gradle.api.artifacts.dsl.RepositoryHandler#maven(org.gradle.api.Action)
I get a similar message within Android Studio when I attempt to Build my project or sync Gradle:
Could not find which method maven() to invoke from this list:
public abstract org.gradle.api.artifacts.repositories.MavenArtifactRepository org.gradle.api.artifacts.dsl.RepositoryHandler#maven(groovy.lang.Closure)
public abstract org.gradle.api.artifacts.repositories.MavenArtifactRepository org.gradle.api.artifacts.dsl.RepositoryHandler#maven(org.gradle.api.Action)
Open File
The line in my build.gradle
file that's failing looks like this:
buildscript {
repositories {
maven () < HERE
jcenter()
google ()
}
// Switch the Android Gradle plugin version requirement depending on the
// installed version of Gradle. This dependency is documented at
// http://tools.android.com/tech-docs/new-build-system/version-compatibility
// and https://issues.apache.org/jira/browse/CB-8143
dependencies {
classpath 'com.android.tools.build:gradle:4.7'
}
}
For context, I have:
Downloaded Android Studio, JDK, and the SDK Tools as well as (in trying to troubleshoot) installed Gradle and Maven via homebrew.
Added the following paths to my .bash_profile
(and confirmed that the file paths contain what they say they do, with matching versions):
export ANDROID_HOME=$HOME/Library/Android/sdk`
export JAVA_HOME=$(/usr/libexec/java_home)
export JRE_HOME=$JAVA_HOME/jre
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export M2_HOME=/usr/local/Cellar/maven/3.5.3/libexec
export M2=$M2_HOME/bin
export PATH=$PATH:$M2_HOME/bin
export PATH=$PATH:/opt/gradle/gradle-4.7/bin
Accepted all license terms via the CLI sdkmanager
Created a Virtual Device via the AVD Manager
Running ionic info
returns the following:
cli packages: (/Users/katesowles/.node/lib/node_modules)
@ionic/cli-utils : 1.19.2
ionic (Ionic CLI) : 3.20.0
global packages:
cordova (Cordova CLI) : 7.0.1
local packages:
@ionic/app-scripts : 1.3.0
Cordova Platforms : android 6.2.3 browser 4.1.0 ios 4.5.4
Ionic Framework : ionic-angular 3.0.1
System:
Android SDK Tools : 26.1.1
ios-deploy : 1.9.2
Node : v8.7.0
npm : 5.4.2
OS : macOS High Sierra
Xcode : Xcode 9.3 Build version 9E145
Environment Variables:
ANDROID_HOME : /Users/katesowles/Library/Android/sdk
Misc:
backend : pro
Running mvn --version
returns
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T11:49:05-08:00)
Maven home: /usr/local/Cellar/maven/3.5.3/libexec
Java version: 1.8.0_171, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.4", arch: "x86_64", family: "mac"
Running gradle --version
returns
------------------------------------------------------------
Gradle 4.7
------------------------------------------------------------
Build time: 2018-04-18 09:09:12 UTC
Revision: b9a962bf70638332300e7f810689cb2febbd4a6c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 1.8.0_171 (Oracle Corporation 25.171-b11)
OS: Mac OS X 10.13.4 x86_64
Any help in finding a way past this and to a completed, successful build would be SO greatly appreciated!
回答1:
After
apply plugin: 'com.android.application'
You should add this:
repositories {
mavenCentral()
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
} // some dependency like this.
}
If you have a maven with authentication you can use:
repositories {
mavenCentral()
maven {
credentials {
username xxx
password xxx
}
url 'http://mymaven/xxxx/repositories/releases/'
}
}
It is important order.
Note : You will need to define the repository outside of buildscript. The buildscript configuration block only sets up the repositories and dependencies for the classpath of your build script but not your application. see this
来源:https://stackoverflow.com/questions/50417839/could-not-find-which-method-maven-to-invoke-from-this-list