mvn No Android SDK path could be found

本文介绍了解决Maven构建Android项目时找不到SDK路径的问题。通过在mac系统中创建并配置setting.xml文件,指定了正确的Android SDK路径,使项目能够成功构建。

下载了个项目, 其中有需要mvn install jar包, 出现了以下错误:

No Android SDK path could be found. You may configure it in the plugin configuration section in the pom file using <sdk><path>...</path></sdk> or <properties><android.sdk.path>...</android.sdk.path></properties> or on command-line using -Dandroid.sdk.path=... or by setting environment variable ANDROID_HOME

解决方案如下:

mac系统中新建mvn的setting.xml如下:

cd ~/.m2

touch setting.xml<!-- 因为之前没有配置过, 不存在setting.xml文件 -->

写入:

复制代码
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
        <profile>
            <id>android</id>
            <properties>
                <android.sdk.path>
                    /Users/lily/android-sdk-macosx <!-- 此处为自己sdk路径 -->
                </android.sdk.path>
            </properties>
        </profile>
    </profiles>
    <activeProfiles> <!--make the profile active all the time -->
              <activeProfile>android</activeProfile>
    </activeProfiles>
</settings>
复制代码

即可解决问题.

[root@yfw ~]# cd /opt/openfire [root@yfw openfire]# cat > install-sdk.sh << 'EOF' > #!/bin/bash > # > # Copyright (C) Jive Software, 2006-2022 > # > # Install the Openfire SDK into your local Maven repository. > # > > set -e > > # Check for required tools > if ! command -v mvn >/dev/null 2>&1; then > echo "Maven is required but not found. Please install Maven." > exit 1 > fi > > VERSION=$1 > if [ -z "$VERSION" ]; then > echo "Usage: $0 <version>" > echo "Example: $0 4.9.2" > exit 1 > fi > > REPO_DIR="$HOME/.m2/repository/org/igniterealtime/openfire/openfire/$VERSION" > > echo "Installing Openfire SDK version $VERSION..." > > # Create target directory > mkdir -p "$REPO_DIR" > > # Download openfire-${VERSION}.jar and openfire-${VERSION}-sources.jar > JAR_URL="https://www.igniterealtime.org/downloadServlet?filename=openfire/openfire_${VERSION}.zip" > > echo "Downloading Openfire distribution package..." > TMP_ZIP=$(mktemp -t openfire-sdk-XXXXXX.zip) > wget -qO "$TMP_ZIP" "$JAR_URL" > > # Extract JAR and POM > unzip -p "$TMP_ZIP" openfire/lib/openfire.jar > "$REPO_DIR/openfire-$VERSION.jar" > unzip -p "$TMP_ZIP" openfire/lib/compile-only/pom.xml > "$REPO_DIR/openfire-$VERSION.pom" > > # Also install sources if available (optional) > if unzip -p "$TMP_ZIP" openfire/src/openfire_src.zip > /dev/null 2>&1; then > unzip -p "$TMP_ZIP" openfire/src/openfire_src.zip > "$REPO_DIR/openfire-$VERSION-sources.jar" > else > touch "$REPO_DIR/openfire-$VERSION-sources.jar" > fi > > # Cleanup > rm -f "$TMP_ZIP" > > echo "[INFO] SDK installed successfully at $REPO_DIR" > echo "[INFO] You can now build Openfire plugins using Maven." > EOF [root@yfw openfire]# [root@yfw openfire]# # 添加可执行权限 [root@yfw openfire]# chmod +x install-sdk.sh [root@yfw openfire]# ./install-sdk.sh 4.9.2 Maven is required but not found. Please install Maven. [root@yfw openfire]# ls ~/.m2/repository/org/igniterealtime/openfire/openfire/4.9.2/ ls: cannot access '/root/.m2/repository/org/igniterealtime/openfire/openfire/4.9.2/': No such file or directory [root@yfw openfire]# # 查看 rpm 是否已安装 maven 包 [root@yfw openfire]# rpm -q maven maven-3.5.4-5.module_el8.0.0+39+6a9b6e22.noarch [root@yfw openfire]# # 查找 mvn 所在位置 [root@yfw openfire]# find /usr -name mvn 2>/dev/null /usr/share/bash-completion/completions/mvn /usr/share/maven/bin/mvn [root@yfw openfire]# ln -s /usr/share/maven/bin/mvn /usr/local/bin/mvn ln: failed to create symbolic link '/usr/local/bin/mvn': Operation not permitted [root@yfw openfire]# mvn -v -bash: mvn: command not found [root@yfw openfire]# export PATH=/usr/share/maven/bin:$PATH [root@yfw openfire]# mvn -v /usr/share/maven/bin/mvn: line 118: build-classpath: command not found Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher [root@yfw openfire]# echo 'export PATH=/usr/share/maven/bin:$PATH' >> ~/.bashrc -bash: /root/.bashrc: Operation not permitted [root@yfw openfire]# source ~/.bashrc manpath: can't set the locale; make sure $LC_* and $LANG are correct [root@yfw openfire]# mvn -v -bash: mvn: command not found [root@yfw openfire]#
10-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值