When I add the dependency:
compile 'net.bytebuddy:byte-buddy-android:0.7.8'
in my app, I get this error:
Conflict with dependency 'net.bytebuddy:byte-buddy'. Resolved versions for app (0.7.8) and test app (0.6.14) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
I have visited http://g.co/androidstudio/app-test-app-conflict and it says:
Gradle build will fail if the main APK and the test APK use the same
library (e.g. Guava) but in different versions.[...] To make the build
succeed, just make sure both APKs use the same version
But I don't know what it means.
Can you help me? Thanks.
build.gradle
...
buildTypes {
all {
//just build some config fields
}
demo.initWith(buildTypes.debug)
demo {
//just build some config fields
}
devel.initWith(buildTypes.debug)
devel {
//just build some config fields
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.gg
//just build some config fields
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
...
You can force the version in your test using:
androidTestCompile 'net.bytebuddy:byte-buddy-android:0.7.8'
You can force the version without adding an extraneous dependency by adding this to your gradle file
configurations.all {
resolutionStrategy {
force 'net.bytebuddy:byte-buddy-android:0.7.8'
}
}
Related
I am doing this first time. Using Facebook SDK for android app.
I am following this tutorial.
https://developers.facebook.com/docs/sharing/android/
My app is gradle 3.2.1
Do I need to use ProGuard here?
What code should I write between the given two codes on this link :
https://developer.android.com/studio/build/shrink-code.html?fbclid=IwAR3hmG6hOtzfyiHa3Sehxa4o2j9vq9sPrk8ZVbr-WWyUDakiskFMZQgloJM
android {
buildTypes {
release {
// Enables code shrinking, obfuscation, and optimization for only
// your project's release build type.
minifyEnabled true
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources true
// Includes the default ProGuard rules files that are packaged with
// the Android Gradle plugin. To learn more, go to the section about
// R8 configuration files.
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
...
}
And another code:
android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
// List additional ProGuard rules for the given build type here. By default,
// Android Studio creates and includes an empty rules file for you (located
// at the root directory of each module).
'proguard-rules.pro'
}
}
flavorDimensions "version"
productFlavors {
flavor1 {
...
}
flavor2 {
proguardFile 'flavor2-rules.pro'
}
}
}
There are some more small codes below it, which one should I add?
Please explain.
As you add ProGuard files you have to add this
useProguard true
in your gradle File(module)
I'm working on a game being exported from Unity as an Android Studio project. When I assemble and run as a debug build, it works as expected. Since we are using multiple 3rd party libraries, there are more than 65K methods, and it generates quite a few DEX files (11 files). Looking in the contents of these DEX files, they are not all full. In fact, most of them contain only a single BuildConfig class, or a bunch of related R classes. In fact, only 2 of the DEX files have anything appreciable in them, classes7.dex and classes11.dex. I don't know how the app even runs; I thought the main activity needed to be in classes.dex for it to work. But in any case everything actually works fine.
However, in release builds, the situation is much, much worse. I'm talking about 109 (one hundred and nine!) DEX files. This appears to simply be much more granular separation of the classes that were originally in the 11 DEX files before, for some reason. And here, things start to break down. On launch, ClassNotFoundExceptions start appearing on some devices, but on others it works fine. The common factor I have seen indicating whether it will work is OS version. All the devices are running Android OS 5.0+, so multidexing is supported natively, but the stable devices are mostly running 6.0+.
The main activity is in classes54.dex, which extends from a class in classes30.dex, which extends from a class in classes106.dex, which extends from Activity. Those classes it can find just fine though. The first class it complains it can't find is over in classes91.dex, for example.
I assume the problem is within the gradle process, since the issue occurs when exporting directly to an APK from Unity or when building within Android Studio. So my question is how do I either:
convince Unity/Android Studio/Gradle to output a sensible number of DEX files, or
Get all devices to look at all the dex files, even when there are 100+, when looking for classes?
Current build.gradle created when exporting from Unity:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
flatDir {
dirs 'libs'
}
google()
}
}
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(name: 'GoogleAIDL', ext:'aar')
implementation(name: 'GooglePlay', ext:'aar')
implementation(name: 'android.arch.lifecycle.runtime-1.0.0', ext:'aar')
//...
//Also included: Google Play, Facebook, Crashlytics, AdMob, Firebase, and more, redacted for convenience
//...
implementation project(':Firebase')
implementation project(':GoogleMobileAdsIronSourceMediation')
implementation project(':GoogleMobileAdsMediationTestSuite')
implementation project(':GoogleMobileAdsPlugin')
implementation project(':GoogleMobileAdsTapjoyMediation')
implementation project(':GooglePlayGamesManifest.plugin')
implementation project(':unity-android-resources')
}
android {
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
targetSdkVersion 27
applicationId 'redacted'
multiDexEnabled true
ndk {
abiFilters 'armeabi-v7a'
}
versionCode 0
versionName '1.0.8'
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress '.unity3d', '.ress', '.resource', '.obb', 'crashlytics-build.properties', 'google-services-desktop.json', 'someotherfiles'
}
signingConfigs {
release {
storeFile file('/path/to/key.keystore')
storePassword 'redacted'
keyAlias 'key'
keyPassword 'redacted'
}
}
buildTypes {
debug {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
jniDebuggable true
//Explicitly sign with release key anyway
signingConfig signingConfigs.release
}
release {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
signingConfig signingConfigs.release
}
}
packagingOptions {
doNotStrip '*/armeabi-v7a/*.so'
}
}
Use multiDex when minSdkVersion before 21,should be config multiDexKeepProguard.
link https://developer.android.com/studio/build/multidex#keep
like this
...
multiDexEnabled true
multiDexKeepProguard file("keep_in_main_dex.pro")
...
keep_in_main_dex.pro
-keep class android.support.multidex.** { *; }
# Those classes or methods used in the Application init
....
If use "Run app" button generate apk, the apk may be contains many dex files.
Use "Build->Make Module 'app'" or command line.
I have discovered a... less than optimal solution. My app is currently targeting 21+ as the min SDK. If I drop it down to 20 or lower, the build process apparently changes. Only 2 DEX files come out. Of course this means I need to support Android 4.4+ instead of 5.0+.
To be clear, the only change I made is to add the line
minSdkVersion 20
above targetSdkVersion 27, which changes how it builds. If I change it to minSdkVersion 21 or any number higher, it goes back to being broken.
Use of Pre-dexing is usually the reason for large number of dex files.
Pre-dexing is the process of iterating through all of the project’s modules and converting them from Java bytecode into Android bytecode. It builds each app module and each dependency as a separate DEX file. This dexOption is used in order to build in an incremental way and speed up the build process as change in one module leads to dexing of that module only.
Please try using following dexOptions in your build.gradle file
android {
...
dexOptions {
preDexLibraries = false
}
}
The above should solve your problem and you won't need to support Android 4.4 for your application.
Looks like there is limit of 100 dex files that can be read while targeting minSdkVersion 21: https://android.googlesource.com/platform/art/+/lollipop-release/runtime/dex_file.cc#303. That is the reason your app is working fine after downgrading the api level to 20.
When I try to generate a signed APK, I found this issue :
10:58 Generate Signed APK: Errors while building APK. You can find the errors in the 'Messages' view.
No cached version of com.android.tools.lint:lint-gradle:26.1.1 available for offline mode.
this is my android studio details :
Android Studio 3.1.1
Build #AI-173.4697961, built on April 4, 2018
JRE: 1.8.0_152-release-1024-b02 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
this block for signing the apk :
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.releaseconfig
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
} signingConfigs {
releaseconfig {
keyAlias 'release_key'
keyPassword 'xxxxx'
storeFile file('xxxxxx)
storePassword 'xxxx'
}
}
Per the Android Studio docs, your top-level build.gradle ought to have the google() repository added. Be sure to add it to the repositories under buildscript AND allprojects.
The latter one is what I missed the first time I edited this today after upgrading and that led directly to a Could not find com.android.tools.lint:lint-gradle:26.1.1. when I tried to build a release APK.
Solved (works for me) changing gradle version in the project build.gradle:
From this
classpath 'com.android.tools.build:gradle:3.1.1'
to this
classpath 'com.android.tools.build:gradle:3.0.1'
I think this version required updated libs and gradle.
try to change to compileSdkVersion 27 and libaries as.
implementation 'com.android.support:support-v4:27.1.0'
and gradle ver,
classpath 'com.android.tools.build:gradle:3.1.0'
Try Setting debug to True in release mode though debuggable should be set to false in release APK but currently this is the solution i get.
release {
debuggable true
}
Update
Adding the following code in gradle to make it work
lintOptions {
checkReleaseBuilds false
}
Check Settings > Build, Execution, Deployment > Compiler to see if Command-line Options contains --offline See this answer.
please open your AndroidStudio and find click File and then find settings.
second you click compiler and then find Command-line Options: remove --offline
lintOptions {
abortOnError false
}
//add this on gradle file inside android tag
Please use Analyze > Inspect Code to inspect your code
If your app could be compiled and running just fine but you failed to generate sign APK. For me, after running inspection it shows me a few errors in my code. I fixed all those errors then I could build sign APK just fine. Check this Answer for more option to fix this
What I want to do & the problem
I updated my Android Studio and Android Gradle Plugin to 3.0.1 and my Gradle Wrapper to 4.1 and can build & deploy my Android Gradle project in release variant on a device via IDE.
However, the following 'Gradle Sync' warning messages are shown:
Warning:Module 'library' has variant 'release' selected, but the modules ['integration-test'] depend on variant 'debug'
The problem here is, that there is no 'release' variant for the integration-test module which uses the 'com.android.test'
plugin.
If I simply try to add a release build type (buildTypes { release {} }) to the :integration-test module I receive:
Error:VariantInputs initialized with no merged manifest report on: DEFAULT
Details about the project (simplified)
The project consists of:
a :library module
an :app module which builds the app's apk and uses the :library module
an :integration-test module which:
uses the "com.android.test" plugin
dependents on the :app module via targetProjectPath ':app' & targetVariant 'debug'
and contains instrumented tests on the :app functions
only contains a 'main' folder (the test plugin does not support others)
This project is build after the Android Test Blueprint as the goal is here that the :app module does not know anything about the integration-test module's existence.
settings.gradle
include :library
include :app
include :integration-test
app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
publishNonDefault true
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
applicationId "xxxxx"
testInstrumentationRunner rootProject.ext.testInstrumentationRunner
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
signingConfigs {
release {
keyAlias 'xxxx'
}
}
buildTypes {
debug {
testCoverageEnabled = true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
// This is needed by the integration-test module (i.e. com.android.test : integration test)
// in order for targetVariant to work without a flavor
publishNonDefault true
testOptions {
unitTests {
// Required so that logging methods do not throw not mocked exceptions in junit tests.
returnDefaultValues = true
}
}
compileOptions {
sourceCompatibility rootProject.ext.sourceCompatibility
targetCompatibility rootProject.ext.targetCompatibility
}
}
dependencies {
// Local dependencies
compile project(':library')
// i cleaned up all the other dependencies as they wouldn't help here
}
Question
Did anyone get an (integration-)test module using the com.android.test plugin to run with Android Gradle Plugin 3.0.1 without getting the "no release variant" error? If so, how can I avoid this error or how can I add such a release variant to a android test plugin based module (if this makes sense at all)?
I was also getting
VariantInputs initialized with no merged manifest report on: DEFAULT.
Then I followed exactly what is outlined in the https://github.com/googlesamples/android-testing-templates/tree/master/AndroidTestingBlueprint
The error went away when I removed release buildType from the `buildTypes' block in the test module's Gradle file.
From this:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
to
buildTypes {
}
I have an Android library project and an app, which uses that library project. In the app's build.gradle file I have ProGuard obfuscate the whole app including the library project code:
//from the app project
buildTypes{
release {
runProguard true
proguardFile 'proguard-project.txt'
}
debug{
runProguard false
}
}
All works well, the lib project and the app project both get obfuscated just fine.
However, I want to build my lib project "standalone", so I can distribute it without the app project. This of course means obfuscating the lib project on its own.
I cannot do this by using the buildTypes code in the lib-projects build.gradle and simply running proGuard, since this would break the app-project build, because then building the app would compile its code agains already-obfuscated lib-project code... :-)
What I need is a possibility to run ProGuard only if I build the lib-project in "standalone" mode, e.g. by passing a parameter, or executing a special task.
Can anyone point me in the right direction?
solved it myself. In the lib-project's build file I have two buildtypes and I publish them both:
publishNonDefault true
and the build types:
buildTypes {
debug {
debuggable true
runProguard false
}
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
this causes the debug and release APK to be created. In my app project's build file I then add an explicit dependency to the debug configuration by stating the dependency as follows:
dependencies{
compile project(path: ':FancyLibProject', configuration: 'debug')
//...
}
Of course in the app-project I also have two build types debug and release, which in turn invoke ProGuard in the same way as for the lib-project.
Note: I omitted the signing configs for the release build - without those the APK will cannot be installed!