androidmavengradleksoap2

Cannot import gradle library in code, although it appears in my external libraries list


I am attempting to import kSOAP2 into my app. I used their instructions to import via Maven and attempted translate it using Gradle. It shows up on the external repositories list, however when I try to add import com.google.code.ksoap2-android.ksoap2-android.3.6.4 it is not found.

Here is my 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'
}


Solution

  • The package name is not necessarily the name of the class that you will need to import (usually it's not). To find the name of the class to import, either go into the package jar and check what the class name is over there or check for usage examples online.

    Examples:

    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;