• Breaking News

    [Android][timeline][#f39c12]

    Thursday, September 3, 2020

    The internals of Android APK build process - Article Android Dev

    The internals of Android APK build process - Article Android Dev


    The internals of Android APK build process - Article

    Posted: 03 Sep 2020 07:16 AM PDT

    The internals of Android APK build process - Article

    Table of Contents

    • CPU Architecture and the need for Virtual Machine
    • Understanding the Java Virtual Machine
    • Compiling the Source Code
    • Android Virtual Machine
    • Compilation Process to .dex
    • ART over Dalvik
    • Understanding each part of the build process.
    • Source Code
    • Resource Files
    • AIDL Files
    • Library Modules
    • AAR Libraries
    • JAR Libraries
    • Android Asset Packaging Tool
    • resources.arsc
    • D8 and R8
    • Dex and Multidex
    • Signing the APK
    • References

    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.

    https://preview.redd.it/91nrrk3twxk51.png?width=1280&format=png&auto=webp&s=a95b8cf916f000e94c6493a5780d9244e8d27517

    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.

    https://preview.redd.it/up2os7juwxk51.png?width=1280&format=png&auto=webp&s=2a290bdc9be86fb08d67228c730329130da3bc63

    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.

    https://preview.redd.it/w2uzoicwwxk51.png?width=1280&format=png&auto=webp&s=b122e0781bf9e9ba236d34a87a636c9218f7ea35

    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.

    https://preview.redd.it/sqychk81xxk51.png?width=217&format=png&auto=webp&s=49445fa42e4aa6f4008114a822f364580649fcdf

    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.

    https://preview.redd.it/g4z3tb95xxk51.jpg?width=831&format=pjpg&auto=webp&s=1cdbaacaf10cc529cccca2ba016583596781ee88

    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.

    https://preview.redd.it/qh9bxsplzxk51.png?width=1280&format=png&auto=webp&s=bc40ba6c69cec2110b7d695fe23df094bf5aea6c

    Understanding each part of the process.

    https://preview.redd.it/obelgd7axxk51.png?width=950&format=png&auto=webp&s=299abcf4798ad4d2de93f4eb18b9d9e70dd54297

    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.

    https://preview.redd.it/hmmlfwhdxxk51.png?width=1280&format=png&auto=webp&s=b2fe2b6ad998594a5364bb6af6b5cbd880a2452c

    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.

    https://preview.redd.it/so424bxwxxk51.png?width=1280&format=png&auto=webp&s=0ad2df5bd194ec770d453f620aae9556e14ed017

    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.

    https://preview.redd.it/kjyychmzxxk51.png?width=1261&format=png&auto=webp&s=18bea3bf9f7920a4701c2db9714dc53ae6cc5f82

    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'.

    https://preview.redd.it/10m8rjl0yxk51.png?width=1468&format=png&auto=webp&s=078c4ab3f41c7d08e7c2280555ef2038cc04c5b0

    References

    https://developer.android.com/studio/build

    https://github.com/dogriffiths/HeadFirstAndroid/wiki/How-Android-Apps-are-Built-and-Run

    https://logmi.jp/tech/articles/322851

    https://android-developers.googleblog.com/2017/08/next-generation-dex-compiler-now-in.html

    https://speakerdeck.com/devpicon/uncovering-the-magic-behind-android-builds-droidfestival-2018

    by androiddevnotes on GitHub

    🐣

    submitted by /u/jiayounokim
    [link] [comments]

    Android Studio extremely slow with autocompletion, code analysis, etc.

    Posted: 03 Sep 2020 12:31 PM PDT

    I'm wondering if anyone else has observed something similar:

    in the past month or two, I observed progressively more problems with AS speed in things like:

    - opening a new file, it takes like 10-20+ seconds for the IDE to "color up" the code (from the initial gray)

    - even when a file is opened (and "colored"), oftentimes I start typing and autocompletion just doesn't work, it takes another several dozen seconds for it to finally "sync up"

    - general random actions just "freeze" for a few seconds

    however, build times are as fast as always.

    - 2018 MBP, 6 core i7, 32 GB RAM. I allocated 4GBs of RAM to AS (never been a problem before). I disabled all the external plugins.

    submitted by /u/AsdefGhjkl
    [link] [comments]

    Can we talk about Fragments again?

    Posted: 03 Sep 2020 10:47 AM PDT

    It's 2020, navigation components are here. Have fragments really improved enough use them now?

    submitted by /u/allholy1
    [link] [comments]

    What architectural pattern do you use in your apps and why?

    Posted: 03 Sep 2020 12:54 AM PDT

    With the ViewModel component Google has implicitly suggested the MVVM pattern for developing Android apps. Yet I see many developers using different approaches, not all of them fit perfectly in the Android architecture components.

    So which pattern do you use and why?

    submitted by /u/iClaude10x
    [link] [comments]

    App to motivate you to not unlock your phone

    Posted: 03 Sep 2020 02:40 AM PDT

    Hi,

    Background

    When I started developing I was looking for good ideas of things to develop. These ideas, unfortunately would not come up when I had time to develop.

    I got an idea that I think I would use but now I do not have the time to develop, in case anyone wants to try and do it.

    Idea

    I would love to have an app that incentivizes or gamifies the act of not unlocking your phone.

    I had thought of something simple. For example, starting from the app "Screen Stopwatch" (source code available), from "Google Creative Lab", it counts the time you have been using your phone and shows it in your lock screen and background.

    I end up not really looking at the time, but if the time went down while I am not using it I might wait until it goes to zero to start using my phone again.

    Additionally, I would add 1 (configurable) minute for every unlock to discourage from unlocking your phone very often.

    That would be a nice start of an app that I would definitely try.

    There are other potential improvements but this post would get too long.

    Thanks!

    submitted by /u/gomi743
    [link] [comments]

    I want to pay the google play developer fee, but I don't have a credit card.

    Posted: 03 Sep 2020 01:07 PM PDT

    Like the title says, I want to pay for the developer's fee, but I don't have a credit card. Where I live credit cards are not common at all, so I don't actually know how they work. But I heard they work by taking a loan from a bank and I don't want to do that, since I have enough money to pay for it, and I don't want to pay the bank interest. Is there a way to become a developer without having a credit card? My possible ways of payment are PayPal and IDeal.

    submitted by /u/Berendbotje_
    [link] [comments]

    SimplerRecyclerView library

    Posted: 03 Sep 2020 01:02 PM PDT

    Hi, RecyclerView boilerplate code done for you, check it out https://github.com/rmielnik/SimplerRecyclerView

    submitted by /u/robsunm
    [link] [comments]

    Thinking of taking the plunge - redoing my very first app, but entirely in Jetpack Compose! But should I?

    Posted: 03 Sep 2020 06:41 AM PDT

    Perhaps it is still too early to take the plunge and develop apps to publish on Google Play Store using Jetpack Compose?

    These are the required features for the remaking of my first app:

    1. Navigation between activities / screens

    2. Offline data persistence

    3. Storing of data in Firebase

    4. Authentication and login to fetch data from Firebase

    5. AdMobs

    6. Services

    7. Dialogue windows

    Are these features already included in JetPack Compose? I see that there are already user-made libraries on Github that I can use for some of these features, but I am wondering if there are already solutions provided by Google in the current alpha release version.

    submitted by /u/RRFdev
    [link] [comments]

    Is it possible to turn my WordPress blog into an app?

    Posted: 03 Sep 2020 11:52 AM PDT

    I need a minimalist app that is linked to my blog so it automatically updates whenever I post new article. Is there a tool to make that happen or do I need to hire a developer, if so how much would it cost to build this app with bare minimum features?

    submitted by /u/StoicPhil
    [link] [comments]

    Dagger Hilt in a multi module project with navigation component

    Posted: 03 Sep 2020 07:11 AM PDT

    I have a base app module with Hilt working and a main navigation graph. I also have a library project with it's own navigation graph. I am able to navigate from the main_graph to the library_graph using an included graph: <include app:graph="@navigation/library\_graph" />

    This is because my app module implements my library project: implementation project(":library")

    See https://medium.com/@hartwich.daniel/multi-module-navigation-with-the-android-architecture-component-82ed028fa1d9

    Now, I also want to use Hilt in my library module. I followed this guide: https://developer.android.com/training/dependency-injection/hilt-multi-module

    But I am unable to reference LoginModuleDependencies.kt in my library project. I cannot implementation project(":app") because that would cause a circular dependency in my project.

    Is it not possible to use these two recommended approaches together?

    submitted by /u/austinn0
    [link] [comments]

    Does big social media giant such as Facebook,Instagram,Reddit etc. use Domain Driven Design as a architecture in their mobile app?

    Posted: 03 Sep 2020 05:01 AM PDT

    FirebaseInstanceId.getInstance().getToken() returns BLACKLISTED everytime

    Posted: 03 Sep 2020 08:09 AM PDT

    I have been receiving device token as BLACKLISTED for an app, on a Galaxy and Pixel device everytime the call for device token is being made.
    To note These devices are not emulators or bots. I have already followed this stackoverflow post without getting much info : https://stackoverflow.com/questions/42136122/why-does-firebase-push-token-return-blacklisted.

    Any idea what are the scenarios in which a app receives device token as BLACKLISTED.

    submitted by /u/tulika15b
    [link] [comments]

    Is it okay here to ask Android programming help? Just joined this sub.

    Posted: 03 Sep 2020 08:00 AM PDT

    If not, please direct me to a suitable subreddit or other sources.

    If yes then I am describing my question below.

    I am not real quick in Android development. I just bought an app template. It is a feed type app. But the problem is if I upload a high-resolution image, the feed really suck while scrolling. It lags too much. So I found the type of code from Stack Overflow that makes photo resolution low without decreasing much quality before uploading. But the problem is I don't know how to implement that in my Android code.

    Pardon for English. I am not a professional Android developer.

    Thanks

    submitted by /u/umangg
    [link] [comments]

    Google Play Console replaces earning reports with billing reports. How can I track earnings now?

    Posted: 03 Sep 2020 03:56 AM PDT

    I wanted to create a monthly tax report this morning, as I noticed that for August there is no earning report anymore in the Play Console. It got replaced by a billing report which only contained one entry of Taiwanese tax for me.

    There is still the sales report but it contains only the local currency and also misses the google cut. Account activities report in the merchant profile does not give information about the actual purchases.

    I really don't understand why they removed the earnings report. Does anyone know an alternative to the earnings report?

    submitted by /u/Plundergamesdev
    [link] [comments]

    Where is a good place to share your app once it's published for the first time?

    Posted: 03 Sep 2020 12:08 AM PDT

    I've published a simple app to automize something I used to do while going to the gym (Counting calories and macros). I'm not planning on making a business out of it but I just want to play around on how I would go about promoting an app once it's released if I ever wanted to. My app is called "Snackr" is on the playstore if anyone is curious. Anyway I don't have much extra money sitting around since I'm a broke college student lol. I published the app around 10 days ago and have around 15 downloads so far without promoting it. I want to start promoting it on Instagram once I add one important feature which would "complete" the app, I'm really unexperienced when it comes to this I have some ideas which I'd love to implement in the upcoming days but I'd love to hear your ideas/opinions as well.

    submitted by /u/dabro225
    [link] [comments]

    I published a simple Android app to update your status using only emoji. Code is on Github: it ties together 3 Firebase services: Auth, Cloud Functions, and Firestore. [link in comments]

    Posted: 03 Sep 2020 07:32 AM PDT

    A weekly newsletter by Mobile Developers Cafe (Curated Android/iOS developer articles, events, Podcasts, Job posts and lot more)

    Posted: 03 Sep 2020 02:55 AM PDT

    [FIXED] Admob Ad Limit Solution On github, Need contributors

    Posted: 03 Sep 2020 05:39 AM PDT

    Creating my first List View

    Posted: 02 Sep 2020 07:22 PM PDT

    I'm trying to create a list view within a fragment. I tried using my own custom adapter but it kept crashing whenever I try to access a list item's textview inside the adapter. Most resources online use the old-school way with findViewById. I'm trying to only use data binding. Any suggestions?

    NitnemFragment.kt

    class NitnemFragment : Fragment() { private lateinit var binding: NitnemFragmentBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { binding = DataBindingUtil.inflate(inflater, R.layout.nitnem_fragment, container, false) val listItems = arrayListOf("1", "2", "3") binding.nitnemListView.adapter = NitnemAdapter(binding.root.context, listItems) return binding.root } } 

    NitnemAdapter.kt

    class NitnemAdapter(val context: Context, val dataSource: ArrayList<String>): BaseAdapter() { private val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater override fun getCount(): Int { return dataSource.size } override fun getItem(position: Int): Any { return dataSource[position] } override fun getItemId(position: Int): Long { return position.toLong() } override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { val binding = NitnemFragmentBinding.inflate(LayoutInflater.from(parent.context), parent, false) val rowView = binding.nitnemListView rowView.setBackgroundColor(Color.BLACK) val titleTextView = binding.nitnemListView.nitnemTitle titleTextView.text = "Testing" // CRASH NULL EXCEPTION return rowView } } 

    nitnem_list_item.xml

    <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/nitnemTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:text="@string/nitnem_morning" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> 

    nitnem_fragment.xml

    <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/frameLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".NitnemFragment"> <ListView android:id="@+id/nitnem_list_view" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> </layout> 
    submitted by /u/alwaysSearching23
    [link] [comments]

    GIF App Development – How to Develop GIF Encoding

    Posted: 03 Sep 2020 03:27 AM PDT

    How to Create a Video Conferencing App like Zoom?

    Posted: 03 Sep 2020 06:03 AM PDT

    Application icon not showing after updating the app title on Google Play

    Posted: 03 Sep 2020 12:38 AM PDT

    I've recently changed the app title on Google play and used the all available 50 characters,
    after the update is published the icon is not showing when you open the app details page on Google play app, it's showing from the search results, but not the details screen, also this issue only on Google play android application, since the web and the desktop version the icon is visible.
    I think it's an urgent issue since it's affecting the conversion rate.
    I contacted Google play support and send an email, their chat is not available
    I'm asking here if someone had this issue before.

    submitted by /u/tamtom995
    [link] [comments]

    No comments:

    Post a Comment

    Fashion

    Beauty

    Travel