Cannot Instant Run: legacy multi-dex on Dalvik runtime - android-studio

When I ran my app, it said that
Cannot Instant Run: legacy multi-dex on Dalvik runtime
Does it means that I can't use Instant Run when I use multi-dex?
I'm using Android Studio beta4.

In order to activate multiDex at old android versions you have to set multiDexEnabled to true, add dependency and extend your application class from MultiDexApplication or launch MultiDex.install(this) in your application class, which will cause legacy multiDex installation.
However since Intant Run can't work with legacy multiDex you have to use normal one. All you need is removing all that code above except of multiDexEnabled flag set to true. This method is only supported by devices with API 21 and above.
Feel free to correct me if something is wrong.

As mentioned in the documentation Instant Run is disabled by Android Studio in case multidex is enabled for API level 20 or lower and app is deployed on API level 20 or lower.
Documentation link

Just remove this line from your ProjectName/app/build.gradle
android {
defaultConfig {
multiDexEnabled true
}
}
remove multiDexEnabled true and you will able to instant run.

Related

im having in android studio while java

FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
6 issues were found when checking AAR metadata:
1. Dependency 'androidx.appcompat:appcompat-resources:1.6.1' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Recommended action: Update this project to use a newer compileSdkVersion
of at least 33, for example 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
2. Dependency 'androidx.appcompat:appcompat:1.6.1' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Recommended action: Update this project to use a newer compileSdkVersion
of at least 33, for example 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
3. Dependency 'androidx.activity:activity:1.6.0' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Recommended action: Update this project to use a newer compileSdkVersion
of at least 33, for example 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
4. Dependency 'androidx.core:core-ktx:1.9.0' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Recommended action: Update this project to use a newer compileSdkVersion
of at least 33, for example 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
5. Dependency 'androidx.core:core:1.9.0' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Recommended action: Update this project to use a newer compileSdkVersion
of at least 33, for example 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
6. Dependency 'androidx.annotation:annotation-experimental:1.3.0' requires libraries and applications that
depend on it to compile against version 33 or later of the
Android APIs.
:app is currently compiled against android-32.
Recommended action: Update this project to use a newer compileSdkVersion
of at least 33, for example 33.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
on).
Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
i just want to solve it

How to enable coroutine debug mode when running an Android App from Android Studio?

I'm getting a coroutine exception while running my Android app in debug mode through Android Studio.
kotlinx.coroutines.JobCancellationException: StandaloneCoroutine was cancelled
From the coroutines debugging documentation, I gather that I might get fuller stack trace information by enabling debug mode of coroutines.
It can be enabled either by setting system property DEBUG_PROPERTY_NAME or by running Java with enabled assertions (-ea flag).
This is where I'm stuck. What is the idiomatic way of achieving this in Android Studio? My project is configured using Gradle, and I am running on Windows. Ideally, there is a way to configure this through Gradle configuration so that coroutines debug mode is enabled for anyone pulling in this project through source control.
I haven't found a way to configure this through Android studio or Gradle. Information on doing so would still be useful to me. But, the following is verified to work; I got a full stack trace.
The "system property" refers to Java System Properties. They can be set at runtime using System.setProperty.
I therefore added the following code to the start of my Application.onCreate().
override fun onCreate() {
// Enable coroutines debug mode in debug builds.
if (BuildConfig.DEBUG) {
System.setProperty(
kotlinx.coroutines.DEBUG_PROPERTY_NAME,
kotlinx.coroutines.DEBUG_PROPERTY_VALUE_ON
)
}
...
}

com.android.tools.r8.a: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)

implementation 'org.apache.poi:poi:5.0.0'
above dependencies work fine when I run on the emulator/phone using Run 'app' but
when I try to build apk then I got the below error.
com.android.tools.r8.a: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
I try below
if I remove dependencies it works fine.
if I update minSdkVersion 21 to 26 then it works fine.
so my problem is
I want to use minsdkversion 21 and also that dependency(this feature(EXCEL FILE) only available to sdkversion>=26)
so how can I achieve the same?
THANK YOU IN ADVANCE.
Right now this is not possible. D8 will only allow compiling code which use invoke-custom and method handles for a minSdkVersion of 26 or higher, as that is the first version where these features are supported by Android.
There is an open issue on lifting that restriction. However, depending on the code in the library this might just end up as a runtime error if the code using invoke-custom and method handles will be hit at runtime on a device with API level of 25 or below.
The reason you can run you code from Android Studio, is that when debugging on a device or emulator, Android Studio will "artificially" raise the minSdkVersion for the build to that of the device or emulator attached. This is to provide the best development experience by taking advantage of what the device or emulator supports.
You can use version 4, it works for me
implementation 'org.apache.poi:poi:4.0.0'
implementation 'org.apache.poi:poi-ooxml:4.0.0'

Can enabling android proguard prevent people decompile my code?

I have an android app, and it seems someone decomiple my code and uploaded to the play store. In my app, I have something that makes a call to my website through a php file like the following
http//www.test.com/get_service.php
Its hardcoded in the app as a string. That guy is making the same call using my get_service.php because whenever I change something in the get_service.php, it would reflected on their app.
I just noticed that apps like https://play.google.com/store/apps/details?id=com.njlabs.showjava&hl=en
is able to decompile my android app.
So I tried enabling the Proguard on my app, and test it on my own phone. I haven't release the app yet, but it seems the app is still able to decompile my code. Is there a way to hide my string? so that even if someone decompile my code, he won't be able to see the get_service.php file.
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'
}
}
...
}

Remove unused resources using Android Studio?

I want to remove unused resources from my project to reduce the app size. Is there any way to do it by using Android Studio IDE efficiently?
The Gradle build system for Android supports Resource Shrinking : the automatic removal of resources that are unused, at build time, in the packaged app. In addition to removing resources in your project that are not actually needed at runtime, this also removes resources from libraries you are depending on if they are not actually needed by your application.
For example, your application is using Google Play Services to for example access Google Drive functionality, and you are not currently using Google Sign In, then this would remove the various drawable assets for the Sign In buttons.
Note: Resource Shrinking only works in conjunction with code shrinking (such as ProGuard). That's how it can remove unused resources from libraries; normally, all resources in a library are used, and it is only when we remove unused code that it becomes apparent which resources are referenced from the remaining code.
To enable resource shrinking, update your build type as follows:
android {
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
And google recently launched Android Studio 2.0 officially, Now they are giving an option in the IDE itself.
Right click on app --> Refactor --> Remove Unused Resources
It will prompt
Check the box prior confirm action so that you can get rid of unused #id declarations too.
In terms of APK optimization consider Selecting a Format fact as well.
Use WebP Images provide better compression than either JPEG or PNG. Lossy WebP images are supported in Android 4.0 (API level 14) and higher, and lossless and transparent WebP images are supported in Android 4.3 (API level 18) and higher.
In android studio. You can use Android Lint. It will show " Strings, Resource, import.." not use
Analyze -> Inspect Code -> Whole Project -> OK

Resources