最近调用的Android应用程序类方法onCreate



我已经重载了Application class in my android app and i'm using IAviaryClientCredentials's的接口。

public class AppypieApplication extends Application implements IAviaryClientCredentials
{
    public ArrayList<BookInformation> bis;
    public SkyDatabase sd = null;
    public int sortType=0;
    public ArrayList<CustomFont> customFonts = new ArrayList<CustomFont>();
    private static AppypieApplication mInstance;
    private static String CREATIVE_SDK_SAMPLE_CLIENT_ID;
    private static String CREATIVE_SDK_SAMPLE_CLIENT_SECRET;
    private QBUser currentUser;
    private MediaPlayerManager soundPlayer;
    private Map<Integer, QBUser> dialogsUsers = new HashMap<Integer, QBUser>();

    @Override
    public void onCreate()
    {
        super.onCreate();
        Toast.makeText(AppypieApplication.this,"AppypieApplication",Toast.LENGTH_LONG).show();
        String applicationId = getString(R.string.app_chrome_cast_id);
        QBSettings.getInstance().fastConfigInit(Consts.QB_APP_ID, Consts.QB_AUTH_KEY, Consts.QB_AUTH_SECRET);
        String manufacturer = android.os.Build.MANUFACTURER;
        System.out.println("device manufacturer==="+manufacturer);
        if (!manufacturer.equalsIgnoreCase("amazon")) {
            try {
                VideoCastManager.initialize(this, CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID, null, null).
                        setVolumeStep(0.5).
                        enableFeatures(VideoCastManager.FEATURE_NOTIFICATION |
                                VideoCastManager.FEATURE_LOCKSCREEN |
                                VideoCastManager.FEATURE_WIFI_RECONNECT |
                                VideoCastManager.FEATURE_CAPTIONS_PREFERENCE);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        CREATIVE_SDK_SAMPLE_CLIENT_ID=getString(R.string.creative_sdk_client_id);
        CREATIVE_SDK_SAMPLE_CLIENT_SECRET=getString(R.string.creative_sdk_secret_id);
        AdobeCSDKFoundation.initializeCSDKFoundation(getApplicationContext());
        if (!manufacturer.equalsIgnoreCase("amazon")) {
            AnalyticsTrackers.initialize(this);
            AnalyticsTrackers.getInstance().get(AnalyticsTrackers.Target.APP);
        }
        initApplication();
        registerActivityLifecycleCallbacks(new ActivityLifecycleHandler());

    }

问题:

  • 案例1:当我从Studio 2.1.1运行代码时,应用程序工作正常

  • 案例2:当我clear-app-data时,大约需要2分钟才能进入应用程序类onCreate()

  • 情况3:当有人第一次使用apk并安装/运行应用程序时,大约需要2分钟才能onCreate()应用程序类,之后它工作正常。

操作系统版本 6.0


更新 1

我的 gradle 文件。

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
    maven { url 'https://maven.fabric.io/public' }
}
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "com.app.kljdrfqwxcqgzzimiygdcwrshoxalmfyuonetatuvj"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 30
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    defaultConfig {
        multiDexEnabled true
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }
    }
    lintOptions{
        disable "ResourceType"
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    dexOptions {
        incremental = true;
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
    }
}
allprojects {
    apply plugin: 'maven'
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "${project.rootDir}/creativesdk-repo/release"
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], exclude: 'android-support-v4.jar',dir: 'libs')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.google.android.gms:play-services:7.+'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile('com.adobe.creativesdk.foundation:auth:0.7.329') {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude module: 'support-v4'
    }
    compile('com.adobe.creativesdk:image:4.0.0') {
        exclude module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    compile('com.android.support:multidex:1.0.1') {
        exclude group: 'com.android.support', module: 'multidex'
    }
    compile files('libs/commons-io-2.4.jar')
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    compile files('libs/aacdecoder-android-0.8.jar')
    compile files('libs/skyepub.jar')
    compile files('libs/httpcore-4.3.jar')
    compile files('libs/anjlab-iabv3-1.0.23.jar')
    compile files('libs/quickblox-android-sdk-chat-2.1.jar')
    compile files('libs/quickblox-android-sdk-content-2.1.jar')
    compile files('libs/quickblox-android-sdk-core-2.1.jar')
    compile files('libs/quickblox-android-sdk-location-2.1.jar')
    compile files('libs/quickblox-android-sdk-messages-2.1.jar')
    compile files('libs/quickblox-android-sdk-videochat-webrtc-2.1.jar')
    compile files('libs/android-support-v4.jar')
    compile 'com.android.support:support-v4:22.2.0'
     compile 'com.android.support:support-annotations:22.2.0'
        compile ('com.android.support:support-v4:23.1.1')
                {
                    force=true
                }
        compile ('com.android.support:support-annotations:23.1.1')
                {
                    force=true
                }
    compile project(':stripe')
    compile 'com.facebook.android:facebook-android-sdk:4.8.0'
    compile project(':vitamio')
    compile project(':zxing-scan')
    compile('com.twitter.sdk.android:twitter:2.0.0@aar') {
        transitive = true;
    }
    compile project(':libraryProject_AppypiePdf')
    compile project(':linkedin-sdk')
    compile project(':CastCompanionLibrary-android')
    compile 'net.ypresto.androidtranscoder:android-transcoder:0.2.0'
    compile project(path: ':de.keyboardsurfer.android.widget.crouton')
    compile project(path: ':pull-to-refresh')
}

更新 2

我在V4图书馆的虚构中发现了一些麻烦,但我设法逃脱了它。 :D

成功生成 apk:

Information:Gradle tasks [:app:assembleDebug]
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(jnamed$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(jnamed$2) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(jnamed$3) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.xbill.DNS.UDPClient$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
Information:BUILD SUCCESSFUL
Information:Total time: 1 mins 44.355 secs
Information:32 errors
Information:0 warnings
Information:See complete output in console

之后在Appypie应用程序上崩溃了.java

日志猫:

01-03 12:44:06.024 30385-30385/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.twheels, PID: 30385
java.lang.NoClassDefFoundError: android.support.v7.media.MediaRouter$GlobalMediaRouter$1
   at android.support.v7.media.MediaRouter$GlobalMediaRouter.<init>(MediaRouter.java:1628)
   at android.support.v7.media.MediaRouter.getInstance(MediaRouter.java:246)
   at com.google.android.libraries.cast.companionlibrary.cast.BaseCastManager.<init>(BaseCastManager.java:189)
   at com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.<init>(VideoCastManager.java:197)
   at com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.initialize(VideoCastManager.java:224)
   at com.app.twheels.AppypieApplication.onCreate(AppypieApplication.java:66)
   at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1036)
   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4728)
   at android.app.ActivityThread.access$1600(ActivityThread.java:154)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:148)
   at android.app.ActivityThread.main(ActivityThread.java:5443)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

应用代码.java:

package com.app.kljdrfqwxcqgzzimiygdcwrshoxalmfyuonetatuvj;
/**
 * Created by maven on 5/25/2016.
 */
public class AppypieApplication extends Application implements IAviaryClientCredentials
{
    public ArrayList<BookInformation> bis;
    public SkyDatabase sd = null;
    public int sortType=0;
    public ArrayList<CustomFont> customFonts = new ArrayList<CustomFont>();
    private static AppypieApplication mInstance;
    private static String CREATIVE_SDK_SAMPLE_CLIENT_ID;
    private static String CREATIVE_SDK_SAMPLE_CLIENT_SECRET;
    private QBUser currentUser;
    private MediaPlayerManager soundPlayer;
    private Map<Integer, QBUser> dialogsUsers = new HashMap<Integer, QBUser>();
    @Override
    public void onCreate()
    {
        super.onCreate();
        String applicationId = getString(R.string.app_chrome_cast_id);
        QBSettings.getInstance().fastConfigInit(Consts.QB_APP_ID, Consts.QB_AUTH_KEY, Consts.QB_AUTH_SECRET);
        String manufacturer = android.os.Build.MANUFACTURER;

        System.out.println("krishna device manufacturer==="+manufacturer);
        if (!manufacturer.equalsIgnoreCase("amazon")) {
            try {
/*
                VideoCastManager.initialize(this, CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID, null, null).
                        setVolumeStep(0.5).
                        enableFeatures(VideoCastManager.FEATURE_NOTIFICATION |
                                VideoCastManager.FEATURE_LOCKSCREEN |
                                VideoCastManager.FEATURE_WIFI_RECONNECT |
                                VideoCastManager.FEATURE_CAPTIONS_PREFERENCE);
*/
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        CREATIVE_SDK_SAMPLE_CLIENT_ID=getString(R.string.creative_sdk_client_id);
        CREATIVE_SDK_SAMPLE_CLIENT_SECRET=getString(R.string.creative_sdk_secret_id);
        AdobeCSDKFoundation.initializeCSDKFoundation(getApplicationContext());
        if (!manufacturer.equalsIgnoreCase("amazon")) {
            AnalyticsTrackers.initialize(this);
            AnalyticsTrackers.getInstance().get(AnalyticsTrackers.Target.APP);
        }
        initApplication();
        registerActivityLifecycleCallbacks(new ActivityLifecycleHandler());

    }

    public void reloadBookInformations()
    {
        this.bis = sd.fetchBookInformations(sortType,"");
    }
    public void reloadBookInformations(String key)
    {
        this.bis = sd.fetchBookInformations(sortType,key);
    }
    @Override
    public String getBillingKey() {
        return "";
    }
    @Override
    public String getClientID() {
        return CREATIVE_SDK_SAMPLE_CLIENT_ID;
    }
    @Override
    public String getClientSecret() {
        return CREATIVE_SDK_SAMPLE_CLIENT_SECRET;
    }
    public static synchronized AppypieApplication getInstance() {
        return mInstance;
    }
    public synchronized Tracker getGoogleAnalyticsTracker() {
        AnalyticsTrackers analyticsTrackers = AnalyticsTrackers.getInstance();
        return analyticsTrackers.get(AnalyticsTrackers.Target.APP);
    }
    public void trackScreenView(String screenName) {
        Tracker t = getGoogleAnalyticsTracker();
        t.setScreenName(screenName);
        t.send(new HitBuilders.ScreenViewBuilder().build());
        GoogleAnalytics.getInstance(this).dispatchLocalHits();
    }
    public void trackException(Exception e) {
        if (e != null) {
            Tracker t = getGoogleAnalyticsTracker();
            t.send(new HitBuilders.ExceptionBuilder()
                    .setDescription(
                            new StandardExceptionParser(this, null)
                                    .getDescription(Thread.currentThread().getName(), e))
                    .setFatal(false)
                    .build()
            );
        }
    }

    public void trackEvent(String category, String action, String label) {
        Tracker t = getGoogleAnalyticsTracker();
        t.send(new HitBuilders.EventBuilder().setCategory(category).setAction(action).setLabel(label).build());
    }
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);;
    }
    public void callQuickBlox(){
        initApplication();
    }
    // for quickblox chat
    private void initApplication() {
        mInstance = this;
//        QBChatService.setDebugEnabled(true);
        initImageLoader(this);
//        QBSettings.getInstance().fastConfigInit(Consts.QB_APP_ID, Consts.QB_AUTH_KEY,
//                Consts.QB_AUTH_SECRET);
        soundPlayer = new MediaPlayerManager(this);
        new PrefsHelper(this);
    }
    private void initImageLoader(Context context) {
        ImageLoader.getInstance().init(ImageUtils.getImageLoaderConfiguration(context));
    }
    public MediaPlayerManager getMediaPlayer() {
        return soundPlayer;
    }
    public QBUser getCurrentUser() {
        return currentUser;
    }
    public void setCurrentUser(QBUser currentUser) {
        this.currentUser = currentUser;
    }
    public Map<Integer, QBUser> getDialogsUsers() {
        return dialogsUsers;
    }
    public void setDialogsUsers(List<QBUser> setUsers) {
        dialogsUsers.clear();
        for (QBUser user : setUsers) {
            dialogsUsers.put(user.getId(), user);
        }
    }
    public void addDialogsUsers(List<QBUser> newUsers) {
        for (QBUser user : newUsers) {
            dialogsUsers.put(user.getId(), user);
        }
    }
    public Integer getOpponentIDForPrivateDialog(QBDialog dialog){
        Integer opponentID = -1;
        for(Integer userID : dialog.getOccupants()){
            if(!userID.equals(getCurrentUser().getId())){
                opponentID = userID;
                break;
            }
        }
        return opponentID;
    }
}

任何建议和帮助将不胜感激。

您必须删除一些正在使用的库。有什么不需要的并且写在gradle文件中吗?

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
    maven { url 'https://maven.fabric.io/public' }
}
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "com.app.kljdrfqwxcqgzzimiygdcwrshoxalmfyuonetatuvj"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 30
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    defaultConfig {
        multiDexEnabled true
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }
    }
    lintOptions{
        disable "ResourceType"
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    dexOptions {
        incremental = true;
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
    }
}
allprojects {
    apply plugin: 'maven'
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "${project.rootDir}/creativesdk-repo/release"
        }
    }
}

dependencies {
    //compile fileTree(include: ['*.jar'], exclude: 'android-support-v4.jar',dir: 'libs')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.google.android.gms:play-services:7.+'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile('com.adobe.creativesdk.foundation:auth:0.7.329') {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude module: 'support-v4'
    }
    compile('com.adobe.creativesdk:image:4.0.0') {
        exclude module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    compile('com.android.support:multidex:1.0.1') {
        exclude group: 'com.android.support', module: 'multidex'
    }
    //compile files('libs/commons-io-2.4.jar')
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    compile files('libs/aacdecoder-android-0.8.jar')
    compile files('libs/skyepub.jar')
    compile files('libs/httpcore-4.3.jar')
    compile files('libs/anjlab-iabv3-1.0.23.jar')
    compile files('libs/quickblox-android-sdk-chat-2.1.jar')
    compile files('libs/quickblox-android-sdk-content-2.1.jar')
    compile files('libs/quickblox-android-sdk-core-2.1.jar')
    compile files('libs/quickblox-android-sdk-location-2.1.jar')
    compile files('libs/quickblox-android-sdk-messages-2.1.jar')
    compile files('libs/quickblox-android-sdk-videochat-webrtc-2.1.jar')
    //compile files('libs/android-support-v4.jar')
    compile 'com.android.support:support-v4:22.2.0'
    // compile 'com.android.support:support-annotations:22.2.0'
    //    compile ('com.android.support:support-v4:23.1.1')
    //            {
    //                force=true
    //            }
    //    compile ('com.android.support:support-annotations:23.1.1')
    //            {
    //                force=true
    //            }
    compile project(':stripe')
    compile 'com.facebook.android:facebook-android-sdk:4.8.0'
    compile project(':vitamio')
    compile project(':zxing-scan')
    compile('com.twitter.sdk.android:twitter:2.0.0@aar') {
        transitive = true;
    }
    compile project(':libraryProject_AppypiePdf')
    compile project(':linkedin-sdk')
    compile project(':CastCompanionLibrary-android')
    compile 'net.ypresto.androidtranscoder:android-transcoder:0.2.0'
    compile project(path: ':de.keyboardsurfer.android.widget.crouton')
    compile project(path: ':pull-to-refresh')
}

愿这有帮助。

最新更新