Why is the release build variant always debuggable? - android

Whether I create the "release" APK by:
Using Generate Signed APK in Android Studio
Select the Release build variant and use Tools -> Build APK
Run the assembleRelease task
... the APK produced always has debuggable=true which I've confirmed by trying to upload them to Google Play, which says:
"Upload failed. You uploaded a debuggable APK. For security reasons you need to disable debugging before it can be published in Google Play."
The (only) manifest has no debuggable attribute specified. Gradle specifies debuggable=false for release, and true for debug, see below.
What am I missing? Where is the debuggable state coming from, and why is the debuggable=false in the release build type declaration being ignored? I do not want to add debuggable=false to the manifest and to have to keep manually enabling/disabling it.
app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
applicationId "com.myapp.android"
minSdkVersion 14
targetSdkVersion 26
versionCode 5
versionName 5
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
storeFile rootProject.file("keystore.jks")
if (storeFile.exists()) {
def config = new Properties()
config.load(new FileInputStream(rootProject.file("keystore.passwords")))
storePassword config.KeystorePassword
keyAlias config.KeyAlias
keyPassword config.KeyPassword
}
}
}
buildTypes {
release {
debuggable false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
debuggable true
applicationIdSuffix ".debug"
}
}
dataBinding {
enabled = true
}
lintOptions {
disable 'RtlHardcoded'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// Copy release APK to project root
task copyReleaseApk(type: Copy) {
from 'build/outputs/apk'
into '..'
include '**/*release.apk'
}
afterEvaluate {
if (tasks.findByPath("packageRelease") == null) {tasks.create("packageRelease")}
tasks.findByPath("packageRelease").finalizedBy(copyReleaseApk)
}
}
ext {
// Single place to specify the support library version
supportLibraryVersion = '26.0.0-beta2'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
exclude module: 'espresso-idling-resource'
exclude group: "javax.inject"
})
implementation 'com.android.support.test.espresso:espresso-contrib:2.2.2'
// Dagger dependency injection
implementation 'com.google.dagger:dagger:2.10'
annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
implementation 'com.google.dagger:dagger-android:2.10'
implementation 'com.google.dagger:dagger-android-support:2.10'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.10'
implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
implementation "com.android.support:design:$supportLibraryVersion"
implementation "com.android.support.constraint:constraint-layout:1.0.2"
implementation "com.jakewharton.timber:timber:4.5.1"
implementation "com.squareup.phrase:phrase:1.1.0"
implementation "com.squareup.retrofit2:retrofit:2.2.0"
implementation "com.squareup.retrofit2:converter-gson:2.2.0"
implementation "com.squareup.okhttp3:logging-interceptor:3.7.0"
implementation 'net.danlew:android.joda:2.9.9'
testImplementation 'junit:junit:4.12'
implementation 'com.google.firebase:firebase-crash:11.0.0'
androidTestImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
Update 1: I tried adding debuggable=false to the manifest and it makes no difference, the APK produced still cannot be uploaded to Google Play.
Update 2: I loaded the APKs back into Android Studio using the APK Analyzer that makes it easy to see the manifest, and they all include.... debuggable=true. Where is it coming from?
Update 3: assembleRelease produces a debuggable APK on both my local machine AND on the CI server (BuddyBuild).
Update 4: A clean rebuild (including deleting the build folders) and restarting Android Studio with its caches cleared makes no difference.
Update 5: It seems reasonable to assume that the debuggable=true state could be coming from one of the dependencies, but if that is the case which, and how can that be overridden?

As the project is targeting API 26 and using 3.0.0-alpha4 of the android gradle plugin, 26.0.0-beta2 build tools, and gradle 4.0-rc1 I thought I should check that the issue does not relate to an issue with these pre-release tools. So I reverted to API 25 and the stable releases of gradle 3.3, gradle plugin 2.3.3 and build tools 25.0.3. This was a little tedious as I had to downgrade all the Java 8 syntax from the source to Java 7. But having done that, the build process now works as expected and produces release APK artifacts that do not contain the debuggable="true" flag and can be uploaded to Google Play. đź‘Ť
I'm not clear specifically where the cause is but I've logged this in the Android tools bug tracker as it seems possible it is a bug:
https://issuetracker.google.com/issues/62899843
UPDATE: The response from the tools team is that this is expected behaviour because the app targets API 26 and that is in preview. I thought as the 26 APIs were final that APKs could be built against it and released to Google Play but clearly not.

This is because you probably have incremental builds, by default all incremental builds are assumed debuggable.
Under the General Notes of the SDK Tools Revision 8, it states:
Support for a true debug build. Developers no longer need to add the
android:debuggable attribute to the tag in the manifest
— the build tools add the attribute automatically. In Eclipse/ADT, all
incremental builds are assumed to be debug builds, so the tools insert
android:debuggable="true". When exporting a signed release build, the
tools do not add the attribute. In Ant, a ant debug command
automatically inserts the android:debuggable="true" attribute, while
ant release does not. If android:debuggable="true" is manually set,
then ant release will actually do a debug build, rather than a release
build.

Related

Android project generating too many DEX files in release builds

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.

generate signed apk is not working, apk is unsigned

I used to generate a signed apk from Android Studio and everything was working well until I updated Android Studio to 3.3. It generates an apk but after I try to install it, it says: App Not Installed!
My Trial was by:
Click on build
Generate Signed Apk
Choose APK and click Next
Insert the Key Store Path, Key Store Password, Key Alias, Key Password
Click Next
Choose Release Variant
Click Finish
The Apk is generated but it's not signed! What is the problem ?
Here is my app build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 27
defaultConfig {
applicationId "com.twobreathe.soft2breathe"
minSdkVersion 23
targetSdkVersion 27
versionCode 9
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
vectorDrawables {
useSupportLibrary true
}
resConfigs "en", "ja"
}
signingConfigs {
release {
keyAlias "[my key alias]"
keyPassword "[my key password]"
storeFile file("[path to the keystore file]")
storePassword "[my store password]"
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
shrinkResources true
pseudoLocalesEnabled false
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/fluidsynth/android/CMakeLists.txt"
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
dataBinding {
enabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '28.0.3'
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.parse-community.Parse-SDK-Android:parse:1.18.4'
implementation 'com.jjoe64:graphview:4.2.2'
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
testImplementation 'junit:junit:4.12'
implementation 'com.orhanobut:hawk:2.0.1'
implementation 'xyz.sahildave:arclayout:1.0.0'
implementation 'com.mikhaellopez:circularprogressbar:2.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
implementation 'com.github.GrenderG:Toasty:1.3.0'
implementation 'com.kyleduo.switchbutton:library:2.0.0'
implementation 'com.github.franmontiel:LocaleChanger:0.9.2'
implementation 'cn.aigestudio.wheelpicker:WheelPicker:1.1.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
}
After updating to 3.3, many problems are occuring related to signing an APK. Sometime it doesn't sign the apk and sometime it says the key is not private.
Well i also faced this problem after upgrading to android studio 3.3 and i resolved in 3 steps. But firstly make sure you backup your whole project.
In Android Studio goto File > Project Structure and untick from "use embedded JDK" then click OK
Goto Computer Settings (system settings) (win + pause key) then go to Advanced system settings>Environment variables. if JAVA_HOME not present then add it and set path to your installed JDK.
As i couldn't find a direct approach to modify jdk path in my project that is upgraded in some way to android studio 3.3 settings, i did following(for the last step) BUT MAKE SURE YOU MAKE BACKUP BEFORE THIS.
To make sure where i am guiding come to project view, I deleted ".grade", ".idea", "capture", "gradle" folders from the root and "build", "release", "lib" folder from "app" leaving "src" as it is. Deleted root.iml and did not delete app.iml file Then rebuild the project and then created the Signed package.
It went successful after 2 try. To be very honest i did the last step twice by restoring files from backup. As deleting these folders i messed up 1 time.
Not strictly related, but I ended up in this questions when searching for a fix to my problem.
In my case I forgot to remove 'debuggable true' for one of my non-debug built-types. When I was generating the bundle the google play store wouldn't complain about it just said that it wasn't signed. But when I tried uploading an apk it showed the true error.
From your Gradle its visible that you have not configured your Signing Config with it.
Please check image below:
Step 1:
Go to your project settings > select your module (Let's say "app") > go to signing > enter proper information and keystore.jks file
Step 2:
Go to Build Types > select Release type > assign signing config as you created on step 1. > after that your gradle will have config as there in image.
Step 3:
Try generating signed APK.
It will be success!!!
Happy Coding..
Double check both of the values on the final dialog, labelled by "Signature Versions".
For more information please check the following link:
https://developer.android.com/about/versions/nougat/android-7.0#apk_signature_v2
Anyway this question seems duplicate as the following:
android studio: release apk is not signed
friend
when you go for build the signed apk
now in android studio 3.3 , you will 2 option for build the signed apk.
1. Android App Bundle
2.APK
i will suggest to use option 2
select option 2 and Click on Next button now studio ask for your password details
now fill all details and
select Remember password checkbox for feature and now next .
now again studio ask for debug and release build confirmation
now here select release and select 2 checkbox at bottom and then continue
hope your signed apk will be generate .
When generating an APK, make sure both the signature types are checked, otherwise Fabric (and other places) may not recognise it as signed.
Additionally you probably want to remove debuggable true from your release config, as debuggable builds can't be uploaded to Google Play. There's a chance this is also causing an issue.
Try to sign it using command-line tools. I may help you to identify the problem.
(https://developer.android.com/studio/build/building-cmdline).
In my case, it was JAVA_HOME problem (as in #Vanshaj Daga answer).

Native code debug is not working in Android Studio 3

I've tried all the ways found on StackOverflow and still facing the issue.
I've created a demo Android project with native support, added a library to it and moved all native code into the library.
Now I'm unable to stop on breakpoints in native code, native debugger became active only after a SEGFAULT crash.
I've added defaultPublishConfig "debug" into mylibrary build.gradle and debuggable true to app build.fradle. There was enough for native debugging earlier. But it is not working since Android Studio upgrade.
Here are the full build.gradle files
app
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.raistlin.myapplication"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(path: ':mylibrary')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
mylibrary
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
defaultPublishConfig "debug"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang"
cppFlags "-fexceptions", "-std=c++11", "-DJSONCPP_NO_LOCALE_SUPPORT"
version "3.10.2"
}
}
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
First, check debug variant is selected for library.
As your build.gradle has a setting, path "src/main/cpp/CMakeLists.txt", it won't build I think. So set targets, rebuild and check again.
If breakpoints doesn't work after build, old garbage may be left in the build cache and causes problems. Open project directory in explorer and delete build cache (.externalNativeBuild folder) manually and build the project again. I also delete build folder, as it contains .so files in intermediate directory, but it's optional.
Android Studio does not clean libraries in the test device. They are overwritten basically, but clear them manually depending on needs. Files are in /data/app/(package name)/lib/(cpu arch.)/.
NB: Synchronize menu of device file explorer does not synchronize properly under lib or (cpu arch.) directory. To synchronize, select /data or /data/app and choose Synchronize.
NB.1 If targets is omitted, Android Studio seems to build no targets. The built output is in (project)/app/build/intermediates/cmake/(flavor)/obj/(cpu architecture). If it seems to work without any targets, check files on device. They confuse test results.
NB.2 debuggable true is for release build to enable debugging. No need to set it for debug build, as debuggable flag is set as default.
NB.3 Seems version dependent but Gradle in Android Studio does not clean .externalNativeBuild tree properly even if clean or rebuild is called, and confuses native code build configs. It was around AS3.0, as I remember.
NB.4 My environment is
Android Stuidio 3.2.1
classpath 'com.android.tools.build:gradle:3.2.1'
gradle-4.7-all
CMake: default(3.6.4111459)
I know there are newer versions for Android Studio, Gradle and CMake but they are buggy, so I chose current environment. As far as I've experienced, Android Studio 3.3, gradle:3.3.0, gradle-4.10.1-all have severe bug in VCS(git). Wrong file contents are shown in editor and build fails, sometimes. Setting CMake version to 3.10.x (3.10.2 for me) also seems buggy.
Here's a copy from my project as a sample, partially modified from original one but may work.
I've checked breakpoints in a library work in Android Studio 3.2.1.
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "0.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'proguard-rules.pro'
externalNativeBuild {
cmake {
cppFlags "-std=c++11"
arguments "-DANDROID_STL=c++_static"
targets "sample"
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Update
targets is mentioned here Guide - Link Gradle to your native library - Specify optional configurations.

Android Studio not generating APK

I have a strange problem that just started with an existing Android Studio 2.3.3 project.
The build process is not automatically generating an APK, in this case app-debug.apk Log shows build is successful, but no APK anywhere in the project directory tree. Manually selecting Build / Build APK works fine, however.
This is a problem when I change the source and click run. The build process is successful, but then get "Error Installing APK" into the emulator (because the APK does not exist).
This problem only happens on the one project, and I was playing around with Espresso earlier. My guess is I changed a setting somewhere, I just cannot figure out which one. What do I need to change to have the APK generated automatically again? build.gradle included.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 16
targetSdkVersion 25
versionCode 2
versionName "0.0.2"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
storeFile file("/home/user/keystore/keystore.jks")
storePassword "xxxxxxxxxxxxxxxxxx"
keyAlias "xxxxxxxxxxxxxxxxx"
keyPassword "xxxxxxxxxxxxxxxxxxx"
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-ads:10.2.4'
compile 'com.google.android.gms:play-services-location:10.2.4'
testCompile 'junit:junit:4.12'
}
Try below solution -
At right side of Android studio you have a gradle option click on that and then click the refresh icon and then check build.
More details follow below link -
apk not generating
My Android Studio does it all the time so I came up with a workaround. Instead of going to Build > Build APK. I simply run the app.
After running the app if you go to build > output > apk in your project directory, you will find your APK over there. Android Studio rarely throws an error when you run the app.
EDIT
This APK does NOT work on physical devices I dont know what the reason is. It runs on emulators though.
Something is not right with the key, maybe it is not on the path... A studio does not report anything then (simply does not build bundle). Click on the folder icon in the key alias field it will be an error if the key is not on the path (fastest check).
Due to many dependencies in Build.gradle android studio takes too much time and then said Request time out. So have a look into Build.gradle.
Do these steps.
First Method: try to minimize the dependencies
Second Method: Add MultiDEX implementation 'androidx.multidex:multidex:2.0.1' this is for androidX.
Third Method: Make class public class ApplicationDelegate extends MultiDexApplication { } then add in Android Manifest File like this in Application tag
<application
android:name=".ApplicationDelegate"
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">

Android application is not working in lower version like Gingerbread

I am trying to developing an application that work in all android version like API level 23 as well as API level 8.While debugging the application it is working perfectly on latest version api, but not working on lower version like Gingerbread.
I try to change minSdkVersion, but this did not solve the issue.
While debugging in lower version it showing error
"Installation failed since the device possibly has stale dexed jars
that don't match the current version (dexopt error). In order to
proceed, you have to uninstall the existing application."
Build.gradle
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:support-v4:21.0.3'
}
android {
compileSdkVersion 22
buildToolsVersion "21.0.0"
defaultConfig {
applicationId "org.linphone"
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
sourceSets {
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
android {
defaultConfig {
multiDexEnabled = true
minSdkVersion
targetSdkVersion
}
}
configurations.all {
exclude group: 'com.android.support', module: 'support-annotations'
}
}
Manifest.xml
<uses-sdk
android:minSdkVersion="9"
/>
You are using gradle, so you should remove uses-sdk declaration form the manifest.xml - gradle adds it it self. Then change minSdkVersion in the build.gradle to equal or lower than your desired one.
Enable your proguard, its probably caused by dex file. It happens when dex file gets larger then buffer size( i.e. contains more than 65k methods).
android {
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Your app has reached 65k methods limit. There are few solutions:
Shrink your code with ProGuard. From the docs:
The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized .apk file that is more difficult to reverse engineer. Because ProGuard makes your application harder to reverse engineer, it is important that you use it when your application utilizes features that are sensitive to security like when you are Licensing Your Applications.
Enable it on build.gradle of your app module:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
You can add your own ProGuard custom rule, read here.
Update SDK Build Tools to the latest version.
Build your app with MultiDex technique.
Additionally, your apply plugin: 'android' must be changed to apply plugin: 'com.android.application'.
I ran into this trying to test on an emulator. My solution was to give the emulator more memory and storage. It appears to be an issue when building with new (ART) tools and deploying to Dalvik.

Categories

Resources