Skip to content

我的方法数没有超过65535,但是我想要分包,请问怎么操作? #15

Open
@Armyoftheworld

Description

@Armyoftheworld

build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'dexknifePlus'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.juziwl.ixiao"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"

    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}
dexKnife{
//必选参数
enabled true //if false,禁用分包插件
//可选参数
//1.如果没有可选参数,将根据enabled决定是否分包。
//2.如果有可选参数,需满足必选参数和可选参数的条件才允许分包
productFlavor 'mock'
buildType 'debug'

/*
*eg:当前productFlavors = dev,buildType = debug,
*参数组合1:enabled = true,productFlavor = dev,buildType = debug 分包
*参数组合2:enabled = true,productFlavor = mock,buildType = debug 不分包
*参数组合1:enabled = true,buildType = debug 所有buildType = debug分包
*参数组合1:enabled = true,productFlavor = dev 所有productFlavor = dev分包
* */

}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'io.reactivex:rxjava:1.1.5'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.hwangjr.rxbus:rxbus:1.0.4'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.github.Aspsine:SwipeToLoadLayout:1.0.3'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
compile 'com.squareup.retrofit2:converter-scalars:2.1.0'
compile 'com.android.support:multidex:1.0.1'
}

dexknife.txt
#为注释符

#-----------主Dex中必要依赖的脚本配置-----------
#默认保留四大组件中其他三大组件(并计算其依赖树),Activity组件选择性保留(使用-just activity 选项),若为空不保留任何Activity
-just activity com.juziwl.ixiao.main.MainActivity

#-----------附加类-----------

如果你想要某个包路径在maindex中,则使用 -keep 选项,即使他已经在分包的路径中.若为空,不保留任意类

#-keep com.ceabie.demo.**

保留单个类.

#-keep android.support.v7.app.AppCompatDialogFragment.class

这条配置可以指定这个包下类在第二及其他dex中.

#-split android.support.v?.**
#将全部类移出主Dex
-split .

不包含Android gradle 插件自动生成的miandex列表.(不使用建议的依赖树,注释掉表示使用,否则-just activity无效)

#-donot-use-suggest

(分割每个dex的方法数上限) 扩展参数:例如 --set-max-idx-number=50000

如果出现 DexException: Too many classes in --main-dex-list, main dex capacity exceeded:

表明限制的方法数小于main dex的必要方法数,调大到合适数值即可

-dex-param --set-max-idx-number=3000

不进行dex分包, 直到 dex 的id数量超过 65536.(设置自动执行分包策略)

#-auto-maindex

显示miandex的日志.

#-log-mainlist

打包的时候还报了一些错,但是打包成功了
Information:Gradle tasks [:emojitest:assembleDebug, :ixiao:assembleDebug]
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.squareup.haha.guava.base.Joiner$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:(com.squareup.haha.guava.collect.Iterables$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:(com.squareup.haha.guava.collect.Iterables$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.
Information:BUILD SUCCESSFUL
Information:Total time: 43.909 secs
Information:24 errors
Information:0 warnings
Information:See complete output in console

我生成class.dex文件有27928个方法,我现在就想分包,请问怎么写?还有上面的问题是什么原因造成的?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions