I recently started to see errors in prelaunch reports after uploading an application to google play console, and this error is -` java.lang.NoClassDefFoundError: aewt` which belongs to com.google.android.youtube application on Nokia 1 device and Huawei P1, there is no solution to avoid it and it can be a blocker for your release, so be warned!
Understanding the flow of the Android APK build process, the execution environment, and code compilation blog post aims to be the starting point for developers to get familiar with the build process of Android APK.
CPU Architecture and the need for Virtual Machine
Unveiled in 2007, Android has undergone lots of changes related to its build process, the execution environment, and performance improvements.
There are many fascinating characteristics in Android and one of them is different CPU architectures like ARM64 and x86
It is not realistic to compile code that supports each and every architecture. This is where Java Virtual Machine is used.
Understanding the Java Virtual Machine
JVM is a virtual machine that enables a computer to run applications that are compiled to Java bytecode. It basically helps us in converting the compiled java code to machine code.
By using the JVM, the issue of dealing with different types of CPU architecture is resolved.
JVM provides portability and it also allows Java code to be executed in a virtual environment rather than directly on the underlying hardware.
But JVM is designed for systems with huge storages and power, whereas Android has comparatively low memory and battery capacity.
For this reason, Google has adopted an Android JVM called Dalvik.
Compiling the Source Code
Our Java source code for the Android app is compiled into a .class file bytecode by the javac compiler and executed on the JVM.
For Kotlin source code, when targeting JVM, Kotlin produces Java-compatible bytecode, thanks to kotlinc compiler.
To understand bytecode, it is a form of instruction set designed for efficient execution by a software interpreter.
Whereas Java bytecode is the instruction set of the Java virtual machine.
Android Virtual Machine
Each Android app runs on its own virtual machine. From version 1.0 to 4.4, it was 'Dalvik'. In Android 4.4, along with Dalvik, Google experimentally introduced a new Android Runtime called 'ART'.
Android users had the option to choose either Dalvik or ART runtime in Android 4.4.
The .class files generated contains the JVM Java bytecodes.
But Android has its own optimized bytecode format called Dalvik from version 1.0 to 4.4. Dalvik bytecodes, like JVM bytecodes, are machine-code instructions for a processor.
Compilation Process to .dex
The compilation process converts the .class files and .jar libraries into a single classes.dex file containing Dalvik byte-codes. This is possible with the dx command.
The dx command turns all of the .class and .jar files together into a single classes.dex file is written in Dalvik bytecode format.
To note, dex means Dalvik Executable.
ART over Dalvik
Since Android 4.4, Android migrated to ART, the Android runtime from Dalvik. This execution environment executes .dex as well.
The benefit of ART over Dalvik is that the app runs and launches faster on ART, this is because DEX bytecode has been translated into machine code during installation, no extra time is needed to compile it during the runtime.
ART and Dalvik are compatible runtimes running Dex bytecode, so apps developed for Dalvik should work when running with ART.
The JIT based compilation in the previously used Dalvik has disadvantages of poor battery life, application lag, and performance.
This is the reason Google created Android Runtime(ART).
ART is based on Ahead - Of - Time (AOT) based compilation process where compilation happens before application starts.
In ART, the compilation process happens during the app installation process itself. Even though this leads to higher app installation time, it reduces app lag, increases battery usage efficiency, etc.
Even though dalvik was replaced as the default runtime, dalvik bytecode format is still in use (.dex)
In Android version 7.0, JIT came back. The hybrid environment combining features from both a JIT compiler and ART was introduced.
The bytecode execution environment of Android is important as it is involved in the application startup and installation process.
Understanding each part of the process.
Source Code
Source code is the Java and Kotlin files in the src folder.
Resource Files
The resource files are the ones in the res folder.
AIDL Files
Android Interface Definition Language (AIDL) allows you to define the programming interface for client and service to communicate using IPC.
IPC is interprocess communication.
AIDL can be used between any process in Android.
Library Modules
Library module contains Java or Kotlin classes, Android components, and resources though assets are not supported.
The code and resources of the library project are compiled and packaged together with the application.
Therefore a library module can be considered to be a compile-time artifact.
AAR Libraries
Android library compiles into an Android Archive (AAR) file that you can use as a dependency for an Android app module.
AAR files can contain Android resources and a manifest file, which allows you to bundle in shared resources like layouts and drawables in addition to Java or Kotlin classes and methods.
JAR Libraries
JAR is a Java library and unlike AAR it cannot contain Android resources and manifests.
Android Asset Packaging Tool
Android Asset Packaging Tool (aapt2) compiles the AndroidManifest and resource files into a single APK.
At this point, it is divided into two steps, compiling and linking. It improves performance, since if only one file changes, you only need to recompile that one file and link all the intermediate files with the 'link' command.
AAPT2 supports the compilation of all Android resource types, such as drawables and XML files.
When you invoke AAPT2 for compilation, you should pass a single resource file as an input per invocation.
AAPT2 then parses the file and generates an intermediate binary file with a .flat extension.
The link phase merges all the intermediate files generated in the compile phase and outputs one .apk file. You can also generate R.java and proguard-rules at this time.
resources.arsc
The output .apk file does not include the DEX file, so the DEX file is not included, and since it is not signed, it is an APK that cannot be executed.
This APK contains the AndroidManifest, binary XML files, and resources.arsc.
This resource.arsc contains all meta-information about a resource, such as an index of all resources in the package.
It is a binary file, and the APK that can be actually executed, and the APK that you often build and execute are uncompressed and can be used simply by expanding it in memory.
The R.java that is output with the APK is assigned a unique ID, which allows the Java code to use the resource during compilation.
arsc is the index of the resource used when executing the application.
D8 and R8
Starting from android studio 3.1 onwards, D8 was made the default compiler.
D8 produces smaller dex files with better performance when compared with the old dx.
R8 is used to compile the code. R8 is an optimized version of D8.
D8 plays the role of dexer that converts class files into DEX files and the role of desugar that converts Java 8 functions into bytecode that can be executed by Android.
R8 further optimizes the dex bytecode. R8 provides features like optimization, obfuscation, remove unused classes.
Obfuscation reduces the size of your app by shortening the names of classes, methods, and fields.
Obfuscation has other benefits to prevent easy reverse engineering, but the goal is to reduce size.
Optimization reduces the DEX file size by rewriting unnecessary parts and inlining.
By doing Desugaring we can use the convenient language features of Java 8 in older devices.
Dex and Multidex
R8 outputs one DEX file called classes.dex.
If you are using Multidex, that is not the case, but multiple DEX files will appear, but for the time being, classes.dex will be created.
If the number of application methods exceeds 65,536 including the referenced library, a build error will occur.
The method ID range is 0 to 0xFFFF.
In other words, you can only refer to 65,536, or 0 to 65,535 in terms of serial numbers.
This was the cause of the build error that occurred above 64K.
In order to avoid this, it is useful to review the dependency of the application and use R8 to remove unused code or use Multidex.
Signing the APK
All APKs require a digital signature before they can be installed or updated on your device.
For Debug builds, Android Studio automatically signs the app using the debug certificate generated by the Android SDK tools when we run.
A debug Keystore and a debug certificate is automatically created.
For release builds, you need a Keystore and upload the key to build a signed app. You can either make an APK file with apkbuilder and finally optimize with zipalign on cmd or have Android Studio handle it for you with the 'Generated Signed Apk option'.
Understanding the internals of Android Stack Architecture and how it relates to Linux blog post aims to be the starting point for developers to get familiar and have an overview of core components in the Android Stack Architecture.
Early Days of Android
Founded in 2003, Android Inc, in the early days began as an operating system for Digital Cameras. Due to the low market for Digital Cameras, the Android Inc teams' intentions slowly diverted to Mobile Devices. Becoming the rivals of then Symbian and Windows Mobile.
Acquired by Google in 2005, the development team worked on an Operating System based on Linux Kernel in shadows until the unveil of Open Handset Alliance in 2007.
Android Stack
By Google, Android is described officially as an open-source, Linux-based software stack created for a wide array of devices and form factors.
The graphical user interface environment, middlewares, libraries, APIs... sitting on top of Linux Kernel and shell binaries are Software Stack Layers that make the bulk of Android and which makes it much more than a variation of the Linux system.
Linux Kernel
Android's Kernel is based on the Long Term Support (LTS) branches of the Linux Kernel.
The kernel provides drivers for filesystem access, process management, hardware, networking.
The Android Kernel differs from vanilla Linux Kernel due to the differences called as Androidisms
Some of the notable Androidisms added to Kernel are IPC Binder, Wavelocks, Low-Memory Killer, Dalvik, and Android Runtime, Anonymous Shared Memory (ashmem), Alarm, paranoid network, RAM console, Physical memory (pmem), Sync driver, Timed Output, and GPIO, memory and logging enhancements.
Android utilizes many unused/less-popular features in desktop distributions of Linux such as control groups, Low Memory Killer Daemon, Security-Enhanced Linux (SELinux), and open source projects like a racoon for VPN, mdns for network service discovery, and many more.
Secure Element
To provide better security, some devices have an embedded Secure Element (SE), which is dedicated, separate tamper-resistant hardware to store cryptographic data.
Hardware abstraction layer
Android runs on TV, Mobile, Refrigerator and almost everywhere that the underlying hardware may greatly differ in its' scope and support.
To solve this the Android stack typically relies on shared libraries provided by manufacturers to interact with hardware.
Android relies on what can be considered a Hardware Abstraction Layer (HAL), although the interface, behavior, and function of abstracted hardware components differ greatly from type to type.
The idea of GPS, sensor, TV, camera, audio, input media components and other components behavior is defined by HAL and how it should behave in Android.
The vendors are still not allowed to make unnecessary modifications so as to not fail the Compatibility Test Suite, Vendor Test Suite.
Native Libraries
The native libraries layer is responsible for providing support for the core features.
The WebKit Web rendering engine, Audio Manager, LIBC, Secure Sockets Layer (SSL), FreeType for rendering fonts, Media, OpenGL ES graphics API, SQLite database, Surface Manager.
Runtime
Before Android 4.4, each Android app would run on its own virtual machine, which is called "Dalvik" which got superseded by the Android RunTime (ART).In Android 4.4, along with Dalvik, Google experimentally introduced a new Android Runtime called "ART" which still today remains the standard.
ART introduces ahead-of-time (AOT) compilation, which can improve app performance.
App runs and launches faster on ART than Dalvik because DEX bytecode gets translated into machine code during installation which means no compilation during runtime and thus seemingly faster!
Because Dalvik requires extra memory for Just-in-time code cache, an app occupies a smaller memory footprint when it runs on ART."
Framework
The Android application creation process is provided by Application frameworks/libraries which allows developers to use the higher-level Kotlin or Java language, rather than low-level C/C++.
The framework includes the basic blocks for building Android applications such as Content Provider, Activity Manager, Location Manager, View System, Package Manager, Notification Manager, Resource Manager, Telephony Manager, Window Manager.
Android frameworks are divided into separate namespaces using the Java package naming and according to their functionality.
Packages in the android.* namespace is available for use by developers.
Packages in com.android.* are internal.
Android also supports most of the standard Java runtime packages in the java.* namespace.
Apps
The topmost layer in the Android Stack is the Applications layer which can be categorized into System apps and user-installed apps.
System apps cannot be uninstalled or changed by users and are read-only in production devices. System apps are included in the OS image, mounted as /system
User-installed apps can be uninstalled at will. Each application lives in a dedicated security sandbox and cannot affect other applications or access their data.
User-installed apps are installed on a dedicated read-write partition, mounted as /data that host user data.
I don't really understand the difference between stateflow and livedata.
Can someone correct me if I'm wrong:
StateFlow has more operators because it's just a Flowable (also something idk) but that means it's already a bit more like Rx than just a LiveData thing?
StateFlow can actually have a default value set it seems like. I don't believe LiveData actually has this ability.
LiveData.value needs to have !! or ? because value is nullable, but with StateFlow the value can be non null?
Hey everyone, wanted to share some promo about my Jetpack Compose Internals course with you, since there might be several people interested, especially now with the cheapest price ever.
After several successful cohort runs and hundreds of engineers joining live, Iāve decided to make theĀ Jetpack Compose InternalsĀ course fullyĀ self-paced and always available.
Why? Because this course was never meant to be limited to fixed dates or restricted by time zones. Itās a deep, technical exploration of Jetpack Compose, and it deserves to be accessible to every Android developer who wants to truly master the framework from the inside out.
š§ What you'll learn
This is not the average Compose course. On this course you will dive deep into topics like:
How theĀ Compose Compiler PluginĀ rewrites your code
The structure and role of theĀ Slot Table
HowĀ recompositionĀ really works behind the scenes
The internals ofĀ remember, recomposition scopes, and skipping
Compiler generated groups, bitmasks, key groups, and more
Compose performance
Working efficiently with Jetpack Compose
And much more
This course is based on my book,Ā Jetpack Compose Internals, but it goes further, showing these concepts in practice, with animations, code walkthroughs, tooling and much more. Find the full outline inĀ composeinternals.com
ā What you get
Lifetime accessĀ to all video modules
One-time payment. No waiting, no subscriptions, no renewals
Instant accessĀ to the private Discord community š„
Free access to theĀ Jetpack Compose internals book
All future updates to the course, automatically included
š° Launch offer: lowest price ever
To celebrate this new format, Iām offering theĀ lowest price the course has ever hadĀ for aĀ limited timeĀ only.
Whether you missed the cohorts or youāve been waiting for the right time to dig deeper into Compose,Ā this is it. Unchain your understanding. Build faster. Debug better. Write smarter UI code.
Note :: This is not a shitpost. Genuinely I love writing in Compose and after trying to setup a new project the "old" way, I just needed an outlet.
Starting a new Android project, picking out the type of new project, always an empty activity, minSDK, the catchy name which will be the next big thing, and there we go, an Android app that launches MainActivity.
There are a couple moving pieces that allow this to work, however. The MainActivity.kt file (assuming we picked Kotlin as the default lang) is current file open on the screen with our new project. It extends a framework Activitytype, and overrides one of its functions, where it calls the setContent passing a static identifier to R.layout.main_activity file. Well, looks like this is probably what the ui of the file is ?
We jump to the R.layout.main_activity file, and are now located in under the res/layouts directory. Seems like a nice separation of concern here, perhaps ? All these R.layout files in this directory however can't go a directory further, so all our layout files are going to be under here. Interesting, maybe our naming conventions can help us navigate to a particular layout file in the future..
The layout file that defines the structure for the UI is written in xml. This hierarchical structure could be a good choice, nested views perhaps makes it easy to create a layout. The preview on the right is great, gives us a good look at what the end result could be. The IDE does a fair job of code suggestions for string parameters on view attributes xml too. Is this going to lock us into the IDE ? It'd been nice to be able to run the project on something slightly lightweight..
Well, lets just make a ui for a list of items. Eventually we can perhaps hook this to a different data source so this list on a screen can give us some useful data. Maybe its a good idea to long story short this experience, from creating a recylcerview, to binding it to the activity using a constant identifier, to creating an adapter, and possibly a viewbinder, double checking we're overriding the correct methods, and there we go again, after another xml file and maybe 2-3 more Kotlin files, we're here with a list of items. We've learnt so much about separation of concern here too, even landed on a couple medium articles about modularization, architecture and what not as we scale, just so we can properly set up our list of items.
Really fun stuff. Our project in Android Studio is a couple kotlin/xml files, we learnt about configuration files like the manifest/gradle, but we have a list showing some data in our app, and the internet taught us a bunch about architecture and the proper way to set this all up.
Clearly this process has lasted the test of time, with enterprise apps appropriately structured able to withstand code changes and maintainence by plenty developers over a long time. How would this all look if some of the fundamentals were cleaner, however.
What if we did remove the need to have a separate language and directory structure for the user interface aspect of our small app. Everything in a single parent directory, and maybe we can modularize it later when it scales. What if the code for the list was structure tighter to a conceptual list and items visualization, rather than an adapter and view specific code as it looks like now.
So, letās ask Amazon and Microsoft their own pair of uncomfortable questions:
Will Amazon agree to distribute Android apps unmodified from what developers upload, with the original signatures intact? Amazonās behavior is policy, and policies can be rescinded.
Will Microsoft commit to having ways to distribute Android apps to Windows 11 users, where those apps are unmodified and retain their original signatures? If we have alternatives to Amazonās AppStore for Android that are reasonable for developers, reasonable for users, and avoid the tampering, that would be a massive win.
Hi! I'm an independent Android developer, together with a friend we created a project Avatar Maker Factory. Our project consists of 27 apps in the Google play developer account. Apps are avatar makers, a program for creating character avatars by the user from the graphic resources contained in the app. In October 2020, Google removed 11 apps from the account for violating the repetitive content rules. Link to your account https://play.google.com/store/apps/dev?id=8637336571588770548 , one of the deleted apps https://play.google.com/stor/apps/details?id=avatarcreatorfactory.princesses.avatarsmaker We are sure that our apps do not violate the rules of repetitive content, because each of the 11 apps and all the other "live" apps have different characters, original graphic resources, package name, banner, description, and screenshots, which will provide a completely different user experience when using the apps. My appeal received a response in which support confirmed the violations and provides examples of violating apps: Avatar Maker: Princess, Avatar Maker: Horses, Avatar Maker: Anime Boys, Avatar Maker: Selfie. Guys, tell me, what can be the same in a princess and a horse, a boy and a girl taking selfies? While using these apps, the user creates a picture of a princess, a horse, a boy, and a girl taking a selfie, which means that each app provides a unique user experience and cannot violate the rules of repetitive content.
I followed the path of the brave guys and wrote an article on Medium and a post here to talk about the unfair handling of Google appeals. I think my appeal was considered not by a human, but by a robot. Perhaps one of you can tell me how I can fix my problem. Thanks!
One of the most common mistakes we see are apps that have buttons and menus that link out to the Play Store -- either to apps by the same developer, or other apps that may be affiliated with the developer, but not being clear that these are ads or promotional links. Without this clarity, apps may get enforced for having deceptive / disguised ads. One of the ways to avoid such mistakes is by explicitly calling these out by labeling the buttons and links as āMore Appsā, āMore Gamesā, āExploreā, āCheck out our other appsā, etc.
And Gmail that has the item "Add to Taks" on the context menu of each email that brings you to the Play Store page of "Google Tasks" follows your rule? If you do not follow your own rules how do you expect developers to do it? If I have an email app can I do the same? And, since I can't, I'm not at a disadvantage in competing with you on this point? Isn't this a typical case of double standards that favors you at the expense of your competitors?
Abandoned and unmaintained apps often create user experience issues -- broken app functionality, for example. Not only are such apps at risk of getting a low star rating and negative user reviews, they will also be flagged as violating the minimum functionality policy. To mitigate the negative impact to the developer reputation and app enforcement, consider unpublishing such apps from the Play Store.
Why don't you also add the possibility to delete an app forever? Do you want to put a minimum publishing time for paid ones, with IAP or with subscription? All right, do it. But give us the possibility to permanently delete the app from your store once these time limits are exceeded.
This is our latest issue with Google's automated processes that have zero human element and include an appeals process that truly feels like a dark hole. Our app is live on Google Play here but our users are sharing with us that our Galaxy Store app install is being flagged by the Play Protect service (see attached for issue). This is the same version offered as a back up on our website. Several of our users have claimed it has warned them or even disabled/removed the app from their device! We are a parental control app so having kids get this prompt is actually quite brave of Google's service here, especially considering our app contains proper user consent and education the permissions we require for our app functionality. We are informing our users to temporarily turn off Play Protect but seems like it doesn't truly get turned off as I had a sticky notification again this morning!
I hope we can defeat the appeals process (2 days waiting already), anyone else have success stories on this one?