无法在代码中导入 gradle 库,尽管它出现在我的外部库列表中
Cannot import gradle library in code, although it appears in my external libraries list
我正在尝试将 kSOAP2 导入到我的应用程序中。我使用他们的说明通过 Maven 导入并尝试使用 Gradle 翻译它。它显示在外部存储库列表中,但是当我尝试添加 import com.google.code.ksoap2-android.ksoap2-android.3.6.4 时找不到。
这是我的 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.mylocationjava"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
mavenCentral()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation files('libs\ksoap2-android-3.6.4.jar')
implementation 'com.google.code.ksoap2-android:ksoap2-android:3.6.4'
}
包名称不一定是您需要导入的 class 的名称(通常不是)。要找到要导入的 class 的名称,请进入包 jar 并检查那里的 class 名称是什么,或者在线查看使用示例。
示例:
https://code.tutsplus.com/tutorials/consuming-web-services-with-ksoap--mobile-21242
https://www.thecrazyprogrammer.com/2016/11/android-soap-client-example-using-ksoap2.html
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
我是这样做的:
build.gradle(模块):
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.code.ksoap2-android:ksoap2-android:3.6.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
settings.gradle:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}
}
rootProject.name = "idt.pda"
include ':app'
}
我正在尝试将 kSOAP2 导入到我的应用程序中。我使用他们的说明通过 Maven 导入并尝试使用 Gradle 翻译它。它显示在外部存储库列表中,但是当我尝试添加 import com.google.code.ksoap2-android.ksoap2-android.3.6.4 时找不到。
这是我的 build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.mylocationjava"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
mavenCentral()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation files('libs\ksoap2-android-3.6.4.jar')
implementation 'com.google.code.ksoap2-android:ksoap2-android:3.6.4'
}
包名称不一定是您需要导入的 class 的名称(通常不是)。要找到要导入的 class 的名称,请进入包 jar 并检查那里的 class 名称是什么,或者在线查看使用示例。
示例:
https://code.tutsplus.com/tutorials/consuming-web-services-with-ksoap--mobile-21242 https://www.thecrazyprogrammer.com/2016/11/android-soap-client-example-using-ksoap2.html
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
我是这样做的:
build.gradle(模块):
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.code.ksoap2-android:ksoap2-android:3.6.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
settings.gradle:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}
}
rootProject.name = "idt.pda"
include ':app'
}