构建Android应用程序出错

时间:2016-02-21 18:33:23

标签: android android-gradle cyanogenmod

当我尝试构建应用时,我遇到了一个奇怪的错误。我不认为它与我的代码有关,需要一些帮助来解决它。当我按下run时,logcat给我这个错误:

无法将stats checkin上传到cyanogen服务器

  

javax.net.ssl.SSLHandshakeException:由peer关闭的连接          在com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(原生方法)                                                                                              在com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:318)                                                                                              在com.android.okhttp.Connection.upgradeToTls(Connection.java:201)                                                                                              在com.android.okhttp.Connection.connect(Connection.java:155)                                                                                              在com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)                                                                                              在com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)                                                                                              在com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)                                                                                              在com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)                                                                                              在com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:217)                                                                                              在com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)                                                                                              在com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)                                                                                              在com.android.settings.cmstats.StatsUploadJobService.uploadToCyanogen(StatsUploadJobService.java:223)                                                                                              在com.android.settings.cmstats.StatsUploadJobService.access $ 000(StatsUploadJobService.java:43)                                                                                              at com.android.settings.cmstats.StatsUploadJobService $ StatsUploadTask.doInBackground(StatsUploadJobService.java:121)                                                                                              at com.android.settings.cmstats.StatsUploadJobService $ StatsUploadTask.doInBackground(StatsUploadJobService.java:93)                                                                                              在android.os.AsyncTask $ 2.call(AsyncTask.java:292)                                                                                              在java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                                              在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:231)                                                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)                                                                                              在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:587)

gradle控制台然后说:

  

意外的顶级例外情况:           com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中:65536               在com.android.dx.merge.DexMerger $ 6.updateIndex(DexMerger.java:484)               在com.android.dx.merge.DexMerger $ IdMerger.mergeSorted(DexMerger.java:261)               在com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:473)               在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:161)               在com.android.dx.merge.DexMerger.merge(DexMerger.java:188)               在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)               在com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)               在com.android.dx.command.dexer.Main.run(Main.java:277)               在com.android.dx.command.dexer.Main.main(Main.java:245)               在com.android.dx.command.Main.main(Main.java:106)

我想知道是否与我的手机硬件或运行在其上的cyanogenmod软件有关,导致错误。

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

您达到了DEX 64k方法限制。

很少有解决方案可以帮助您解决此问题:

  • 删除未使用的gradle依赖项
  • 用较小的方法替换带有较小方法的库,例如:

    cbo1.SelectedItem = luckyStudent;
    

    - >

    compile 'com.google.android.gms:play-services-analytics:8.4.0'
    
  • 通过配置ProGuard

  • 删除未使用的代码
  • 启用Multidex

    的build.gradle

    compile 'com.google.android.gms:play-services-base:8.4.0'
    compile 'com.google.android.gms:play-services-location:8.4.0'
    compile 'com.google.android.gms:play-services-maps:8.4.0'
    ...
    

    的AndroidManifest.xml

    android {
        ...
    
        defaultConfig {
            ...
            // Enabling multidex support.
            multiDexEnabled true
        }
        ...
    }
    
    dependencies {
        compile 'com.android.support:multidex:1.0.0'
    }
    

参考:

Building Apps with Over 65K Methods

答案 1 :(得分:0)

这一行com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536表明你已超过编译器对每个.dex文件的64k方法限制。阅读它。解决方案包括使用Multidex或更多解决方案https://www.contentful.com/blog/2014/10/30/android-and-the-dex-64k-methods-limit/。这可能与其他问题重复。看着 How to solve the issue with Dalvik compiler limitation on 64K methods?