2017-10-13 107 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。 –