简体   繁体   中英

Android Studio Gradle dependency doesn't show up in External Libraries

I'm using Android Studio 3.0.1 and I'm trying to add an online dependency and while Gradle initially syncs without a problem it doesn't show my dependency in External Libraries and my code that references the dependency doesn't work.

Here's a snippet of what my build.gradle file looks like:

repositories {
    mavenCentral()
    maven { url 'https://oss.sonatype.org/content/groups/public/' }
}

dependencies {
    compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT'
}

I'm pretty new to android development (took over an existing project from a dev who quit without leaving any documentation) so I'm not sure if this is a mistake with how to add a project dependency or if there is a problem with the dependency that I'm trying to add. Any help would be greatly appreciated!

I was able to get this to work by changing the dependency declaration to:

compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT', classifier: 'jar-with-dependencies'

The library artifacts up on the repository include an apklib and a JAR with a special classifier. The apklib format is not supported by Android Studio, and unfortunately the classifier on the JAR means that it's not accessible simply using the group-name-version format when declaring dependencies.

Your build.gradle file seems fine. If you want to keep the library specified as an external library, you can try and define the dependency using the alternative notation, replace:

compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT'

with:

compile 'com.fortysevendeg.android:swipelistview:1.0-SNAPSHOT'

The alternative approach is to download the jar file yourself and use it as a local dependency. If you navigate to the maven repository you can inspect the package which is included as a dependency and download the jar directly . Place the jar file in the libs folder of your project and add the following to your build.gradle file:

compile fileTree(dir: 'libs', include: ['*.jar'])

For further details on how to configure the dependencies of your gradle project, check out the Android Studio documentation here.

Based on the information you have provided, this should fix your issues. If this does not solve the error then there may be other issues with the project.

Your dependencies should not placed in the top-level build.gradle file where the repositories are defined. There is even a comment in that file that says so, by default.

You app dependencies should be the module's build.gradle along with the others like android-support

Additionally, that library is very old, and is a SNAPSHOT build, meaning it isn't meant to be generally used in a release environment. You should find an alternative... And there are plenty of other ListView swiping ones

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM