2017-10-13 100 views
2

我有一个Gradle项目中已连接Android测试的库模块,但测试APK引用的方法太多,需要多指标或应启用ProGuard。Multidex Andoird Library模块

有没有一种方法可以为连接的Android测试应用程序启用multidex或ProGuard?

它没有意义,直接对库启用ProGuard的,但如果有一种方法,使之只为androidTest配置,这将很好地工作。

我们为应用程序模块启用了ProGuard,因此它可以安全地依赖此库模块并成功构建应用程序的APK。

由于我只能找到关于使用Multidex支持库的信息,所以很难搜索这个问题的解决方案。我了解如何为典型应用程序启用它。

+0

据我所知,Proguard只用于代码混淆。这与Proguard没有关系。 –

+0

@ReazMurshed ProGuard可以混淆代码,但它也可以删除未使用的方法和类。 https://developer.android.com/studio/build/shrink-code.html –

回答

1

有没有一种方法可以使连接Android测试应用程序的multidex或ProGuard?

是的,您可以启用ProGuard仅用于使用专用测试构建类型的测试。默认的是debug。 在下面的示例中,专用测试构建类型名为minifiedTest

android { 

    defaultConfig { 

     /* Your configs here. */ 

     // Specify the name of the dedicated test build type. 
     testBuildType 'minifiedTest' 
    } 

    buildTypes { 
     debug { 
      // Your debug configurations. 
     } 

     release { 
      // Your release configurations. 
     } 

     minifiedTest { 
      // Use this to get the initial configurations from another build type. 
      // Some of them will be overridden from the configurations specified in this build type. 
      // You can avoid to use this or you can get them from your release build type for example. 
      initWith(debug) 
      // Enable proguard. 
      minifyEnabled true 
      // Specify the proguard file. 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 
+0

感谢您的建议。不幸的是,如果库依赖于其他库项目,这种方法会导致一些新版gradle(4.1+)的问题。 我最终只是为库模块启用multidex。 –