我正在尝试创建一个扩展MultidexApplication的Android应用程序类。
public class MyApplication extends MultiDexApplication {
@Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
registerParseSubClasses();
parseInit();
}
private void registerParseSubClasses() {
//registering subclasses
ParseObject.registerSubclass(UserPlace.class);
ParseObject.registerSubclass(PlaceItem.class);
ParseObject.registerSubclass(PlaceItemRating.class);
}
private void parseInit() {
Parse.initialize(new Parse.Configuration.Builder(getBaseContext())
.applicationId("MYAPPID")
.server("MyURL")
//.enableLocalDataStore()
.build());
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
ParseFacebookUtils.initialize(this);
}
}
我的Android Manifest看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pnametala.application" >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
这是我的傻瓜:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.pnametala.application"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.parse:parse-android:1.13.1'
compile 'com.google.maps.android:android-maps-utils:0.4.3'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.weiwangcn.betterspinner:library:1.1.0'
compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.facebook.android:facebook-android-sdk:4.15.0'
compile 'com.parse:parsefacebookutils-v4-android:1.10.3@aar'
}
如果我在我的AndroidManifest.xml中使用MultidexApplication,它就像一个魅力,但我需要输入一些不能在没有它的情况下完成的init覆盖。
堆栈跟踪是:
无法实例化应用程序com.pnametala.application.MyApplication:java.lang.ClassNotFoundException:未找到类&#34; com.pnametala.application.MyApplication&#34; on path:DexPathList [[zip file&#34; /data/app/com.pnametala.application-1.apk"],nativeLibraryDirectories = [/ data / app-lib / com.pnametala.application-1,/ vendor / lib,/ system / lib]]
任何人都知道解决方案吗?
答案 0 :(得分:0)
将此添加到build.gradle
dexOptions {
javaMaxHeapSize "4g"
}
答案 1 :(得分:0)