今天教大家3种方法导入Android的第三方库
1、在Android视图下,Module APP的build.gradle文件。
可以看到与android并列的有个dependencies,在这里导入需要的包。比如implementation 'cn.pedant.sweetalert:library:1.3'
就是我导入的github上的UI框架。
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.2.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'cn.pedant.sweetalert:library:1.3'
}
2、导入Module
File——>Import Module,然后选择我们需要导入的library文件。
3、手动导入
将需要导入的jar包或者类包复制粘贴到libs文件夹下,然后右击Add As Library,即可导入。
以上三种方法,都能在Project Structure中查看到包是否被导入。