Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems encountered when developing apps with Android 14

I found that after my app reached a fair size (e.g. by adding multiple libraries), running the app threw java.lang.SecurityException: writable dex file '.../code_cache/.overlay/base.apk/classes2.dex' is not allowed.

If I then remove most of the libraries leaving only those that were added by default, and run again, it could work. But then if I add a tiny bit of code, like a log, it could fail with the same error.

If I want it to run without this error, I have to uninstall the app and then run again from Android Studio. This is very inconvenient, because every time I make some changes, I have to uninstall the app. I wouldn't imagine anyone would like to develop Android apps like this.

Does anyone know a solution to this problem?

like image 488
Wei Wen Avatar asked Nov 29 '25 13:11

Wei Wen


2 Answers

I was also having this problem, so I took a look at this documentation DexClassLoader, and decided to do this.

package com.example

import android.app.Application

class BaseApp : Application() {
    override fun onCreate() {
        super.onCreate()
         val dexOutputDir: File = codeCacheDir
         dexOutputDir.setReadOnly()
    }
}

Just putting dexOutputDir.setReadOnly() in my application solved the problem

Uninstall and reinstall the app again

like image 146
AllanRibas Avatar answered Dec 02 '25 03:12

AllanRibas


For me updating Android Studio to the newest version fixed a problem.

like image 24
KyluAce Avatar answered Dec 02 '25 02:12

KyluAce



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!