How to add a jar in External Libraries in android studio

前端 未结 14 2281
北海茫月
北海茫月 2020-11-22 16:17

I am new to Android Studio. What I need to do is add a few jar files in the External Libraries below the < JDK > folder.

14条回答
  •  长发绾君心
    2020-11-22 16:35

    If anyone is looking for another solution without actually copying the jar file(s) into the project directory, e.g. when using a jar in multiple projects:

    Open build.gradle and add

    def myJarFolder = 'C:/Path/To/My/Jars'
    
    [...]
    
    dependencies {
        [...]
        compile fileTree(dir: myJarFolder + '/jar/Sub/Folder/1', include: ['*.jar'])
        compile fileTree(dir: myJarFolder + '/jar/Sub/Folder/2', include: ['*.jar'])
        [...]
    }
    

    Note that of course you don't have to use the myJarFolder variable, I find it useful though. The path can also be relative, e.g. ../../Path/To/My/Jars.
    Tested with AndroidStudio 3.0

    Update: For Gradle Plugin > 3.0 use implementation instead of compile:

    dependencies {
            [...]
            implementation fileTree(dir: myJarFolder + '/jar/Sub/Folder/1', include: ['*.jar'])
            implementation fileTree(dir: myJarFolder + '/jar/Sub/Folder/2', include: ['*.jar'])
            [...]
        }
    

提交回复
热议问题