简体   繁体   English

无法在Android Studio中添加外部库?

[英]Can't add External Library in Android Studio?

I Added a External Library to my project by following this method . 我通过以下方法向项目添加了外部库。 and tried this method too this method too . 并尝试了这种方法 Gradle build got Finished and i got this line added to my build.gradle Gradle构建完成,我将这一行添加到了build.gradle

compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.1'

Now i am trying to import this library in my class. 现在,我正在尝试在我的课程中import该库。 But i can't do this. 但是我做不到。 I took a look at the files and they are located in the build directory under the exploded-aar . 我看了看文件,它们位于exploded-aar下的build目录中。 so i added @aar to the compile line. 所以我在编译行中添加了@aar Still there are no changes. 仍然没有变化。

How can i import this library to my class or where i am going wrong? 我如何将这个库导入我的班级或哪里出了问题?

Thanks in Advance 提前致谢

Well, you don't need to download anything or point your dependency to a file. 好吧,您无需下载任何内容或将依赖项指向文件。

This dependency, as most of the dependencies you use, can automatically fetched from JCenter , biggest repository for Java and Android components. 与您使用的大多数依赖项一样,该依赖项可以从JCenter (Java和Android组件的最大存储库)自动获取。

All you need to do is: 您需要做的只是:

  1. Add JCenter as your dependencies repository. 将JCenter添加为依赖项存储库。
  2. Declare that you need the library-circular dependency. 声明您需要library-circular依赖。 This can be found and copy/pasted from the file icon in particular package/version in JCenter. 可以在JCenter中的特定程序包/版本中找到并复制/粘贴文件图标。
  3. Resync your Android Studio project with your Gradle build file. 将您的Android Studio项目与Gradle构建文件重新同步。 This is the 'sync' button in Gradle pane in Android Studio. 这是Android Studio中Gradle窗格中的“同步”按钮。

Here's what your build.gradle should include: 这是您的build.gradle应该包括的内容:

repositories {
    jcenter()
}

dependencies {
    compile(group: 'com.github.castorflex.smoothprogressbar', name: 'library-circular', version: '1.0.1', ext: 'aar')
}

in build. 在建立。 gradle put following code dependencies { compile fileTree (dir: 'libs', include: ['*.jar']) gradle放置了以下代码依赖项{编译fileTree(dir:'libs',include:['* .jar'])

} }

Did you add the dependencies? 是否添加了依赖项?

You can do so in the following way - 您可以通过以下方式进行操作-

dependencies {
compile files('insert ParentFolder/external_library_name with the extension here')
}

Add it to build.gradle based in the app folder 将其添加到基于app文件夹的build.gradle

1.Put the jar file into the libs folder. 1.将jar文件放入libs文件夹。

2.Right click it and hit 'Add as library'. 2.右键单击它,然后单击“添加为库”。

3.Ensure that compile files('libs/abcdef.jar') is in your build.gradle file and Finally add the dependencies. 3.确保编译文件('libs / abcdef.jar')在build.gradle文件中,最后添加依赖项。

Eg. 例如。

dependencies {

    compile fileTree(dir: '../jar', include: '*.jar')

    compile project(':pull-to-refresh')

    compile files('libraries/abcdef.jar')
}

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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