将kSOAP依赖项添加到Gradle项目

Axe*_*NuS 26 android gradle ksoap2 maven

我正在尝试使用Gradle在我的Android项目中使用kSOAP.

这是我的项目的build.gradle文件:

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'
}
Run Code Online (Sandbox Code Playgroud)

该库似乎包含在项目和编译DOES工作,但当我尝试导入一个类(即SoapObject)时,似乎命名空间甚至不存在.有趣的是,其他图书馆(如ACRA或Guava)工作正常.我怎么解决这个问题?

Jen*_*ens 46

我正在使用@ amitav13的解决方案,但存储库的URL已更改:

repositories {
        maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases' }
    }
Run Code Online (Sandbox Code Playgroud)

截至目前的当前版本是3.6.0

compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.0'
Run Code Online (Sandbox Code Playgroud)

这确实对我有用.


Sam*_*Sam 33

这让我有点想弄清楚,但我终于得到了它的工作.我一直在研究解析KSoap的WSDL解析器,最后只通过导入ksoap来解决Gradle问题.无论如何,这是你如何做到这一点.

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'

}
Run Code Online (Sandbox Code Playgroud)

当然我的是一个服务库,所以你可能想使用apply plugin:'android'.希望这有助于并节省一些时间.


ami*_*v13 31

这是Sam建议的build.gradle的最小版本,对我有用:

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'
}
Run Code Online (Sandbox Code Playgroud)

请注意,这是应用程序的build.gradle,我没有对项目build.gradle进行任何修改.


Nam*_*nav 12

repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
}
Run Code Online (Sandbox Code Playgroud)

和依赖内部

compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.1'
Run Code Online (Sandbox Code Playgroud)