无法在代码中导入gradle库,尽管它出现在我的外部库列表中

问题描述 投票:0回答:1

我正在尝试将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'
}
android maven gradle ksoap2
1个回答
0
投票

包名称不一定是您将需要导入的类的名称(通常不是)。要找到要导入的类的名称,请进入程序包jar并检查那里的类名称,或者在线查看用法示例。

示例:

https://code.tutsplus.com/tutorials/consuming-web-services-with-ksoap--mobile-21242https://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;
© www.soinside.com 2019 - 2024. All rights reserved.