Adding kSOAP dependency to Gradle project
Asked Answered
H

8

33

I'm trying to make kSOAP working in my Android project with Gradle.

This is my project's build.gradle file:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()

    maven {
        url 'http://ksoap2-android.googlecode.com/svn/m2-repo'
    }
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 18
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
    compile 'ch.acra:acra:4.5.0'
    compile 'com.google.guava:guava:12.0'
    compile 'com.google.code.ksoap2-android:ksoap2-android:3.0.0'
}

The library seems to be included in the project and compilation DOES work but when I try to import a class (ie SoapObject) it seems like the namespace does not even exist. The funny thing is that the other libraries (such as ACRA or Guava) are working fine. How can I solve this problem?

Hanny answered 12/9, 2013 at 21:7 Comment(2)
This can be a problem with android studio (I asume you use one). Did you try to write a code (that uses kSOAP) and then building the project from commandline?Spurge
I did and it did not compile at all. It tells me "error: package org.ksoap2.serialization does not exist" on the import and "error: cannot find symbol" on the first SoapObject variable definition.Hanny
U
37

This took me a bit to figure out as well, but I have finally gotten it working. I've been working on a WSDL parser that parses for KSoap and finally got that working only to fight through Gradle with the import of ksoap. At anyrate here is how you do it.

apply plugin: 'android-library'

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
        classpath 'com.google.code.ksoap2-android:ksoap2-android:3.1.1'
    }
}

repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}


android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

dependencies {

    compile 'com.google.code.ksoap2-android:ksoap2-android:3.1.1'

}

Of course mine is a service library, so you may want to use apply plugin: 'android'. Hopefully this helps and saves somebody some time.

Unicuspid answered 28/1, 2014 at 22:48 Comment(3)
Thank you! Finally I got it working with Gradle. It took me some time to fix it but now it works.Hanny
Not working for me, it compiles but won't run on my device 'ClassNotFoundException' so I'm back with jar file ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar, I don't know if it is because of dependencies (don't think so because it's the maven's power) ... Thanks anyway for sharing this ;)Cimbura
actually compile 'com.google.code.ksoap2-android:ksoap2-android:3.1.1' dont work!Myrlmyrle
B
49

I am using @amitav13's solution but the URL of the repository has changed:

repositories {
        maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases' }
    }

Current version as of now is 3.6.0

compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.0'

This did work for me.

Bailable answered 22/1, 2016 at 20:57 Comment(0)
U
37

This took me a bit to figure out as well, but I have finally gotten it working. I've been working on a WSDL parser that parses for KSoap and finally got that working only to fight through Gradle with the import of ksoap. At anyrate here is how you do it.

apply plugin: 'android-library'

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
        classpath 'com.google.code.ksoap2-android:ksoap2-android:3.1.1'
    }
}

repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}


android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

dependencies {

    compile 'com.google.code.ksoap2-android:ksoap2-android:3.1.1'

}

Of course mine is a service library, so you may want to use apply plugin: 'android'. Hopefully this helps and saves somebody some time.

Unicuspid answered 28/1, 2014 at 22:48 Comment(3)
Thank you! Finally I got it working with Gradle. It took me some time to fix it but now it works.Hanny
Not working for me, it compiles but won't run on my device 'ClassNotFoundException' so I'm back with jar file ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar, I don't know if it is because of dependencies (don't think so because it's the maven's power) ... Thanks anyway for sharing this ;)Cimbura
actually compile 'com.google.code.ksoap2-android:ksoap2-android:3.1.1' dont work!Myrlmyrle
W
35

Here's a more minimal version of the build.gradle suggested by Sam that works for me:

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "20.0.0"

defaultConfig {
    applicationId "com.example.test"
    minSdkVersion 15
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    repositories {
        maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases' }
    }
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.2'
}

Note that this is the app's build.gradle, I have not made any modifications to the project build.gradle.

Wardroom answered 31/10, 2014 at 15:38 Comment(3)
@amitav13, do you still need the .jar file for your example to work? if not you could probably do without the line 'compile fileTree(...) right?Awed
@Awed no I don't. I left that in there since this was the the default generated build file, plus the code to get kSoap working.Wardroom
@amitav13 Thank you. After few hours of struggle and trying every other answer this is the one that worked! But the repository address is changed. you should update that :)Eada
C
14
repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}

and inside Dependencies

compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.1'
Cryptoclastic answered 17/8, 2016 at 7:0 Comment(0)
I
3

I was in the same situation. And I gave up to add that jar from mavencentral.

I added the raw jar as a lib.

  1. Download the latest (or whatever version) of ksoap2-android from this url
  2. Call it in the build.gradle, see below

Here is the code:

dependencies {
   compile files('libs/ksoap2-android.jar')
}

I hope it will help.

Iives answered 2/12, 2013 at 9:26 Comment(2)
I totally gave up on Gradle instead. For small projects it's an overkill!Hanny
@AxelGeNuS, yea. I was in the same situation. But It is really efficient even it is for small project. You should try it again when you got some free time. :)Iives
S
3

These answers are pretty old and none of them worked for me. Here is my solution using Android Studio 3.1.4 and ksoap 3.6.4

android gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myapp.aspservicetest"
        minSdkVersion 24
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        repositories {
            maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases' }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.code.ksoap2-android:ksoap2-android:3.6.4'
}
Sarad answered 30/6, 2019 at 0:43 Comment(2)
Finally! Thank you!Buggy
This worked for me once I deleted the pre-existing copy of the ksoap jar file from my /libs/ directory.Agricola
T
1

More simple solution is just download the .jar from http://www.bvbcode.com/code/ed5zc936-1814251-down and add this .jar file to your libs folder.

Finally in your build.gradle:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs') 
}

This worked fine for me.

Tellurion answered 24/8, 2016 at 7:37 Comment(0)
B
0

I know there are already answers using a jar file. I wanted to add one with the latest updated links:

Download ksoap2-android-assembly-3.6.4-jar-with-dependencies.jar and add it to folder libs.

in build.grade:

android {
...
    configurations {
        all {
            exclude group: 'com.squareup.okhttp3', module: 'okhttp'
        }
    }
}
...
dependencies {
...
 implementation fileTree(include: '*.jar', dir: 'libs')
...
}
Borrero answered 10/12, 2019 at 0:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.