Android new project no code, apk is 4 mb

半世苍凉 提交于 2020-01-23 17:05:13

问题


I'm creating a simple pro package to unlock features in my free app.

My free app will check if the pro package is installed and unlock pro features if its installed. I created a new project, with no activity. When I pushed it the app to my device it says it's 4 mb in size. Why is it so big when theres no code? Looking at other apps with pro unlockers, they seem very small like 100-200 kb.

build.gradle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.dsmartapps.root.kerneltoolkitunlocker"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
}

Solution: simply removed compile 'com.android.support:appcompat-v7:22.0.0' and its now 48.00kb.


回答1:


Probably has to do with the your Gradle build file. It's probably using the support library, if you have no use of it you can remove it.

EDIT:

Even so, as Jared said a single support library shouldn't make your apk size that big. You should check your dependencies and assets to see what makes up for that size.

Here's a simple Gradle file for a new project:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.edd.myapplication"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
   }
   buildTypes {
       release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
       }
   }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

Size with compile 'com.android.support:appcompat-v7:21.0.3': around 900kb.

Size without it: around 22kb.



来源:https://stackoverflow.com/questions/29785088/android-new-project-no-code-apk-is-4-mb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!