29

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?

Axel GeNuS
  • 490
  • 1
  • 4
  • 10
  • 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? – Nikita Skvortsov Sep 13 '13 at 06:49
  • 1
    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. – Axel GeNuS Sep 14 '13 at 06:47

8 Answers8

48

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.

Jens
  • 5,615
  • 1
  • 45
  • 71
34

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.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Sam
  • 4,979
  • 1
  • 21
  • 35
  • Thank you! Finally I got it working with Gradle. It took me some time to fix it but now it works. – Axel GeNuS Feb 22 '14 at 21:14
  • 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 ;) – Bibu Jul 01 '14 at 18:38
  • actually compile 'com.google.code.ksoap2-android:ksoap2-android:3.1.1' dont work! – David Hackro Jun 27 '16 at 17:07
34

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.

Erfan GLMPR
  • 898
  • 1
  • 12
  • 14
amitavk
  • 1,057
  • 1
  • 12
  • 13
  • @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? – Brabbeldas Dec 10 '14 at 11:04
  • @Brabbeldas 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. – amitavk Dec 10 '14 at 17:48
  • @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 :) – Erfan GLMPR Jan 19 '17 at 17:50
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'
Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Naman Vaishnav
  • 1,030
  • 1
  • 13
  • 22
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.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Swan
  • 846
  • 1
  • 8
  • 23
  • I totally gave up on Gradle instead. For small projects it's an overkill! – Axel GeNuS Dec 03 '13 at 09:56
  • @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. :) – Swan Dec 03 '13 at 13:17
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'
}
gmmo
  • 2,152
  • 3
  • 22
  • 46
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.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
buzzingsilently
  • 1,375
  • 1
  • 10
  • 17
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')
...
}
Hong
  • 15,059
  • 14
  • 64
  • 105