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

805 Views Asked by At

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'
}

2

There are 2 best solutions below

0
Maram El-Salamouny On BEST ANSWER

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;
0
Herman Van Der Blom On

I have done it like this:

build.gradle (module):

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'

    }