2016-07-21 46 views
-1

我搜索了很多问题,但唯一可以找到的答案是重构onCreate中的代码以启用快速启动。但这个问题在我的情况下看起来不同。 我和我的团队成员正在研究通过GITHUB同步的代码,由他制作的构建在Flash中打开,由我制作的构建需要超过10秒才能启动。 另一个问题,他的构建是90MB左右,我的构建只有30MB。应用程序无论如何功能齐全,但启动时间和构建尺寸的差异太大。Android应用程序启动时间过长

我不确定他的系统配置,但我使用JAVA8编译,SDK 24和Gradle 2.10来构建应用程序。

这里是我的gradle这个文件

buildscript { 
    repositories { 
     jcenter() 
     /*flatDir { 
      dirs 'libs' 
     }*/ 
     maven { url 'https://maven.fabric.io/public' } 
    } 

    dependencies { 
     //compile(name:'library-release', ext:'aar') 
     classpath 'io.realm:realm-gradle-plugin:0.88.0' 
     classpath 'io.fabric.tools:gradle:1.21.2' 
    } 
} 
apply plugin: 'com.android.application' 
apply plugin: 'realm-android' 
apply plugin: 'io.fabric' 

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


android { 
    compileSdkVersion 24 
    buildToolsVersion '24.0.0' 

    useLibrary 'org.apache.http.legacy' 
    dexOptions { 
     maxProcessCount 4 // this is the default value 
     javaMaxHeapSize "4g" 
     dexInProcess = false 
    } 

    defaultConfig { 
     applicationId "com.sample.app" 
     minSdkVersion 21 
     targetSdkVersion 24 
     versionCode 31 
     versionName "1.0" 
     multiDexEnabled true 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     /*debug { 
      minifyEnabled true 
      useProguard false 
     }*/ 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    sourceSets { 
     main { 
      java.srcDirs = ['src/main/java'] 
     } 
     robolectric { 
      java.srcDir file('src/test/java/') 
     } 
    } 

} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile('com.twitter.sdk.android:twitter:[email protected]') { 
     transitive = true; 
    } 
    testCompile 'org.robolectric:shadows-play-services:3.0' 
    testCompile 'org.robolectric:shadows-support-v4:3.0' 
    testCompile 'org.powermock:powermock-module-junit4:1.6.2' 
    testCompile 'org.powermock:powermock-module-junit4-rule:1.6.2' 
    testCompile 'org.powermock:powermock-api-mockito:1.6.2' 
    testCompile 'org.powermock:powermock-classloading-xstream:1.6.2' 
    testCompile 'junit:junit:4.12' 
    testCompile 'org.robolectric:robolectric:3.0' 
    testCompile 'org.assertj:assertj-core:1.7.0' 
    androidTestCompile 'com.android.support:support-annotations:24.0.0' 
    androidTestCompile 'com.android.support.test:runner:0.4' 
    androidTestCompile 'com.android.support.test:rules:0.4' 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
    compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
     transitive = true; 
    } 

    // compile(group: 'com.google.gms', name: 'google-services', version: '2.0.0-beta4', ext: 'pom') 
    //apply plugin: 'com.android.application' 
    compile 'com.google.android.gms:play-services:9.2.1' 
    compile 'com.google.android.gms:play-services-location:9.2.1' 
    compile 'com.google.android.gms:play-services-gcm:9.2.1' 
    compile 'com.mcxiaoke.volley:library:1.0.15' 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
    compile 'com.android.support:support-v4:24.0.0' 
    compile 'com.android.support:appcompat-v7:24.0.0' 
    compile 'com.android.support:design:24.0.0' 
    compile 'com.android.support:recyclerview-v7:24.0.0' 
    compile 'com.facebook.android:facebook-android-sdk:4.7.0' 
    compile 'com.squareup.okhttp3:okhttp:3.2.0' 
    compile 'com.coinbase.android:coinbase-android-sdk:1.0.1' 
    compile 'org.roboguice:roboguice:2.0' 
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.14' 
    compile 'com.sprylab.android.texturevideoview:texturevideoview:1.1.1' 
    compile 'com.google.code.gson:gson:2.4' 
    compile 'com.google.android.gms:play-services-ads:9.2.1' 
    compile 'com.google.android.gms:play-services-auth:9.2.1' 
} 
//put 'com.google.gms.google-services' plugin at the bottom 
apply plugin: 'com.google.gms.google-services' 
+1

APK的大小不应该是那么不同!知道他正在使用哪个IDE /版本,以及如果你们两个都使用相同的资源等等可能是有用的.30和90MB大小似乎很奇怪。 – Sufian

+0

是的,我知道@Sufian,我们已经匹配资源,他们几乎一样。我们都使用Android Studio 2.1.2 –

+0

请参阅此主题以及http://stackoverflow.com/questions/22064591/apk-size-is-bigger-than-expected-android-studio – Sufian

回答

6

如果仅在调试模式下发生的,所以你可以尝试禁用即时运行

首选项>构建,执行,部署>即时运行

并在那里取消选中“启用即时运行...”

+0

我不排除即时运行导致这样的怪异。它一直如此混乱。 – Sufian

+0

的权利,但只是为了检查这是否是问题 – Yoni

+0

它的工作,应用程序运行速度更快,大小从30MB更改为120MB。运作良好,但如果您可以提供此行为的任何链接或解释,它将会更有帮助。 –

-1

有时候是由于主线程执行的任务更多。 它减慢了应用程序的启动速度。 避免主线程中的更多任务。

+0

正如我的问题的第一行中提到的,它不是因为主线程或onCreate问题。不过谢谢你的尝试。 –