微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

[Android][Maven] 找不到 androidx 工件

如何解决[Android][Maven] 找不到 androidx 工件

我想将我的 aar 库包推送到 Github 包。 我用我的 github 包链接和所有依赖项创建了一个 pom.xml 文件

这里是 pom.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mypackage.package</groupId>
    <artifactId>myartifact</artifactId>
    <packaging>aar</packaging>
    <version>0.0.1</version>
    <name>My Package</name>
    <url>https://mywebsite.com</url>

    <build>
        <plugins>
            <plugin>
                <groupId>com.simpligility.maven.plugins</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>4.1.0</version>

                <extensions>true</extensions>
                <configuration>
                    <sign>
                        <debug>false</debug>
                    </sign>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>4.1.1.4</version>
        </dependency>
        <dependency>
            <groupId>androidx.lifecycle</groupId>
            <artifactId>lifecycle-extensions</artifactId>
            <version>2.2.0</version>
            <type>pom</type>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>androidx.fragment</groupId>
            <artifactId>fragment</artifactId>
            <version>1.3.3</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>androidx.recyclerview</groupId>
            <artifactId>recyclerview</artifactId>
            <version>1.2.0</version>
            <type>pom</type>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>androidx.recyclerview</groupId>
            <artifactId>recyclerview-selection</artifactId>
            <version>1.1.0</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>com.android.volley</groupId>
            <artifactId>volley</artifactId>
            <version>1.2.0</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>androidx.appcompat</groupId>
            <artifactId>appcompat</artifactId>
            <version>1.2.0</version>
            <type>pom</type>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.google.android.material</groupId>
            <artifactId>material</artifactId>
            <version>1.3.0</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>androidx.legacy</groupId>
            <artifactId>legacy-support-v4</artifactId>
            <version>1.0.0</version>
            <type>pom</type>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <repositories>
        <repository>
            <id>maven_central_repo</id>
            <name>Maven repo</name>
            <url>https://maven.google.com/</url>
        </repository>
    </repositories>

    <distributionManagement>
        <repository>
            <id>github</id>
            <name>GitHub Packages</name>
            <url>https://maven.pkg.github.com/myrepo/myrepo</url>
        </repository>
    </distributionManagement>
</project>

在部署时,我收到以下错误The following artifacts Could not be resolved: androidx.fragment:fragment:jar:1.0.0

我收到了从 Google Maven 存储库下载的所有 androidx 依赖项的错误

似乎我的文件将 androidx.fragment 作为 jar 文件获取,即使我将类型指定为 pom

如何获取 androidx 依赖项?

感谢您的帮助。

解决方法

尝试使用 maven-publish 插件自动生成您的 pom 文件并发布。有一个例子 here

apply plugin: 'maven-publish'

// Because the components are created only during the afterEvaluate phase,you must
// configure your publications using the afterEvaluate() lifecycle method.

afterEvaluate {
    publishing {
        publications {
            // Creates a Maven publication called "release".
            release(MavenPublication) {
                // Applies the component for the release build variant.
                from components.release

                // You can then customize attributes of the publication as shown below.
                groupId = 'com.example.MyLibrary'
                artifactId = 'final'
                version = '1.0'
            }
            // Creates a Maven publication called “debug”.
            debug(MavenPublication) {
                // Applies the component for the debug build variant.
                from components.debug

                groupId = 'com.example.MyLibrary'
                artifactId = 'final-debug'
                version = '1.0'
            }
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。