问题
The issue I have is that I have an existing project that depends on Parse. My question is how do I integrate Adobe CreativeSDKImage because it extends MultiDexApplication whereas Parse Application (Class) extends Application.
Existing Project e.g (MyApp extends Application ) import android.app.Application;
CreativeSDK based on ADOBE CREATIVE SDK IMAGE GUIDE e.g (CreativeSDKImageSampleApp extends) import android.support.multidex.MultiDexApplication;
After hours of trying to figure out why my app now crashes everytime it starts-up, I noticed Parse.initilize is the issue or perhaps correct me if I'm wrong, as I also suspect extends MultiDexApplication might be the cause. I read limitations of using MultiDexApplication here for your reference; BUILDING MULTIDEX
So please look at the code below to help me in the integration of Parse with CreativeSDKImage Application.
package com.aviary.android.sample;
import android.support.multidex.MultiDexApplication;
import com.aviary.android.feather.sdk.IAviaryClientCredentials;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseUser;
public class MyApplication extends MultiDexApplication implements IAviaryClientCredentials {
@Override
public void onCreate() {
super.onCreate();
init();
}
private void init() {
// Enable Local Datastore.
Parse.enableLocalDatastore(getApplicationContext());
// Add your initialization code here
Parse.initialize(this);
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
// defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
@Override
public String getBillingKey() {
return "";
}
@Override
public String getClientID() {
return "YOUR CLIENT ID";
}
@Override
public String getClientSecret() {
return "YOUR CLIENT SECRET";
}
}
I am getting this error when I run the code;
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: FATAL EXCEPTION: main
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: Process: com.aviary.android.sample, PID: 3700
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: java.lang.NoSuchMethodError: No virtual method setFollowRedirects(Z)V in class Lcom/squareup/okhttp/OkHttpClient; or its super classes (declaration of 'com.squareup.okhttp.OkHttpClient' appears in /data/app/com.aviary.android.sample-1/base.apk)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at com.parse.ParseOkHttpClient.<init>(ParseOkHttpClient.java:58)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at com.parse.ParseHttpClient.createClient(ParseHttpClient.java:45)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at com.parse.ParsePlugins$Android.newHttpClient(ParsePlugins.java:175)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at com.parse.ParsePlugins.restClient(ParsePlugins.java:91)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at com.parse.Parse.initialize(Parse.java:196)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at com.parse.Parse.initialize(Parse.java:161)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at com.aviary.android.sample.MyApplication.init(MyApplication.java:22)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at com.aviary.android.sample.MyApplication.onCreate(MyApplication.java:14)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at android.app.ActivityThread.-wrap1(ActivityThread.java)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-29 16:09:56.741 3700-3700/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-29 16:0
Build Gradle is below
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
project(':external:calendar') {
apply plugin: 'android-library'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
}
project(':external:colorpicker') {
apply plugin: 'android-library'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
}
project(':external:datetimepicker') {
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:22.2.1'
}
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
}
project(':external:timezonepicker') {
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:22.2.1'
}
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
}
project(':external:ex:chips') {
apply plugin: 'android-library'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
}
apply plugin: 'com.android.application'
dependencies {
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:design:22.2.1'
compile project(':external:calendar')
compile project(':external:colorpicker')
compile project(':external:datetimepicker')
compile project(':external:timezonepicker')
compile project(':external:ex:chips')
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
compile project(':ParseUI-Login')
}
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'external/ex/common/java']
// NOTE: this includes external/ex/common/java!
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
/*
* To sign release build, create file gradle.properties in ~/.gradle/ with this content:
*
* signingStoreLocation=/home/key.store
* signingStorePassword=xxx
* signingKeyAlias=alias
* signingKeyPassword=xxx
*/
if (project.hasProperty('signingStoreLocation') &&
project.hasProperty('signingStorePassword') &&
project.hasProperty('signingKeyAlias') &&
project.hasProperty('signingKeyPassword')) {
println "Found sign properties in gradle.properties! Signing build…"
signingConfigs {
release {
storeFile file(signingStoreLocation)
storePassword signingStorePassword
keyAlias signingKeyAlias
keyPassword signingKeyPassword
}
}
buildTypes.release.signingConfig = signingConfigs.release
} else {
buildTypes.release.signingConfig = null
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
回答1:
It's probably because the aviary image component is using okhttp 1.6.0 while parse uses version 2.4.0 of the same library.
If you run gradle :dependencies
on your project you will notice that only okhttp:1.6.0 is being linked.
If you updated your gradle dependencies, adding okhttp 2.*, it should work (just tested quickly though):
compile 'com.adobe.creativesdk:image:4.0.0'
compile 'com.parse.bolts:bolts-android:1.2.1'
compile 'com.parse:parse-android:1.10.3'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
来源:https://stackoverflow.com/questions/33417118/how-to-integrate-creativesdkimage-with-an-exisiting-parse-android-project