有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我重载了Application class in my 安卓 app and i'm usingIAviaryClientCredentials`接口

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 = 安卓.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:当Iclear-app-data时,大约需要2分钟才能到达应用程序类的onCreate()

  • 案例3:当有人第一次使用apk并安装/运行应用程序时,大约需要2分钟才能到达应用程序类的onCreate(),然后它就可以正常工作了

OS Version 6.0


更新1

我的gradle档案

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.安卓.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

安卓 {

    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-安卓.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.安卓.support', module: 'support-v4'
    }

}

allprojects {
    apply plugin: 'maven'
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "${project.rootDir}/creativesdk-repo/release"
        }
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], exclude: '安卓-support-v4.jar',dir: 'libs')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.安卓.support:appcompat-v7:22.2.0'
    compile 'com.安卓.support:design:22.2.0'
    compile 'com.google.安卓.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.安卓.support', module: 'support-annotations'
        exclude module: 'support-v4'
    }
    compile('com.adobe.creativesdk:image:4.0.0') {
        exclude module: 'support-v4'
        exclude group: 'com.安卓.support', module: 'support-annotations'
    }
    compile('com.安卓.support:multidex:1.0.1') {
        exclude group: 'com.安卓.support', module: 'multidex'
    }
    compile files('libs/commons-io-2.4.jar')
    compile files('libs/YouTubeAndroidPlayerApi.jar')
    compile files('libs/aacdecoder-安卓-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-安卓-sdk-chat-2.1.jar')
    compile files('libs/quickblox-安卓-sdk-content-2.1.jar')
    compile files('libs/quickblox-安卓-sdk-core-2.1.jar')
    compile files('libs/quickblox-安卓-sdk-location-2.1.jar')
    compile files('libs/quickblox-安卓-sdk-messages-2.1.jar')
    compile files('libs/quickblox-安卓-sdk-videochat-webrtc-2.1.jar')
    compile files('libs/安卓-support-v4.jar')
    compile 'com.安卓.support:support-v4:22.2.0'
     compile 'com.安卓.support:support-annotations:22.2.0'
        compile ('com.安卓.support:support-v4:23.1.1')
                {
                    force=true
                }
        compile ('com.安卓.support:support-annotations:23.1.1')
                {
                    force=true
                }
    compile project(':stripe')
    compile 'com.facebook.安卓:facebook-安卓-sdk:4.8.0'
    compile project(':vitamio')
    compile project(':zxing-scan')
    compile('com.twitter.sdk.安卓:twitter:2.0.0@aar') {
        transitive = true;
    }
    compile project(':libraryProject_AppypiePdf')
    compile project(':linkedin-sdk')
    compile project(':CastCompanionLibrary-安卓')
    compile 'net.ypresto.安卓transcoder:安卓-transcoder:0.2.0'
    compile project(path: ':de.keyboardsurfer.安卓.widget.crouton')
    compile project(path: ':pull-to-refresh')
}

更新2

我在确认V4库时发现了一些问题,但我还是设法逃脱了D

Sucessfully apk generated:

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

在那之后,应用程序崩溃了。爪哇

日志:

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

应用程序的代码。爪哇:

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 = 安卓.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;
    }

}

如有任何建议和帮助,将不胜感激


共 (1) 个答案

  1. # 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')
    }
    

    希望这有帮助