如何在“Android Studio”中为Android应用程序创建APK文件

时间:2015-01-24 09:30:43

标签: android android-studio

(Mac OS X 10.9.5,Android Studio 1.1 Preview 1) 我下载了this app.

它(某种程度上)是一个gradle项目。 我改变了一些事情。现在,我想创建AKP。

手册说:

  
      
  1. 在Android Studio中打开项目

  2.   
  3. 打开配置文件/app/src/main/java/com/robotemplates/webviewapp/WebViewAppConfig.java   并根据需要设置常量(更多信息见下文)

  4.   
  5. 打开主构建脚本/app/build.gradle并根据需要设置常量(有关详细信息,请参见下文)

  6.   
  7. 在控制台中运行gradlew assemble

  8.   
  9. APK应该在/ app / build / outputs / apk目录中可用

  10.   

1)我做了。

2)我做到了。在那里,我有:

    package com.company.app_name;

    public class WebViewAppConfig {
        // true for enabling debug logs, should be false in production release
        public static final boolean LOGS = false;

        // true for enabling Google Analytics, should be true in production release
        public static final boolean ANALYTICS = true;

        // true for enabling Google AdMob, should be true in production release
        public static final boolean ADMOB = true;

        // true for opening webview links in external web browser rather than directly in the webview
        public static final boolean OPEN_LINKS_IN_EXTERNAL_BROWSER = false;

        // list of file extensions for download,
        // if webview URL ends with this extension, that file will be downloaded via download manager,
        // keep this array empty if you do not want to use download manager
        public static final String[] DOWNLOAD_FILE_TYPES = {
                ".zip", ".rar", ".pdf", ".doc", ".xls",
                ".mp3", ".wma", ".ogg", ".m4a", ".wav",
                ".avi", ".mov", ".mp4", ".mpg", ".3gp"
        };
    }

3)我有:

        // Main build script for WebView App
        // 
        // Usage: gradlew assembleDebug           Build debug APK
        //        gradlew assembleRelease         Build production APK
        //        gradle wrapper                  Create Gradle Wrapper


        final VERSION_MAJOR = 1 // max two digits
        final VERSION_MINOR = 2 // max two digits
        final VERSION_PATCH = 0 // max two digits
        final VERSION_BUILD = 0 // max three digits


        apply plugin: 'com.android.application'


        dependencies
        {
            compile 'com.android.support:support-v4:20.+'
            compile 'com.android.support:appcompat-v7:20.+'
            compile 'com.google.android.gms:play-services:4.4.+'
            compile fileTree(dir: 'libs', include: ['*.jar'])
        }


        android
        {
            compileSdkVersion 19
            buildToolsVersion "21.1.1"

            defaultConfig
            {
                minSdkVersion 10
                targetSdkVersion 19
                versionCode VERSION_MAJOR*10000000 + VERSION_MINOR*100000 + VERSION_PATCH*1000 + VERSION_BUILD
                versionName "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
            }

            signingConfigs
            {
                release
                {
                    // passwords and alias are obtained via askForPasswords task
                    storeFile file("../${project.property('keystore.file')}")
                    storePassword ""
                    keyAlias ""
                    keyPassword ""
                }
            }

            buildTypes
            {
                debug
                {
                    versionNameSuffix "-debug"
                }

                release
                {
                    signingConfig signingConfigs.release
                    zipAlignEnabled true
                    minifyEnabled false
                    shrinkResources false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                }
            }

            applicationVariants.all
            {
                variant ->
                    if(variant.buildType.name.equals("release"))
                    {
                        variant.outputs.each
                        {
                            output ->
                                def outputFile = output.outputFile
                                def date = new Date()
                                if(outputFile!=null && outputFile.name.endsWith('.apk'))
                                {
                                    def fileName = outputFile.name.replace(
                                            "app",
                                            "webviewapp-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + "-" + date.format('yyyyMMdd'))
                                    output.outputFile = new File((String) outputFile.parent, (String) fileName)
                                }
                        }
                    }
            }
        }


        task askForPasswords <<
        {
            def storePass
            def keyAlias
            def keyPass

            def keystorePropertiesFile = new File(project.property("keystore.properties"))

            if(project.hasProperty("keystore.properties") && keystorePropertiesFile.exists())
            {
                println "Loading keystore passwords from property file..."
                Properties properties = new Properties()
                properties.load(new FileInputStream(keystorePropertiesFile))
                storePass = properties['keystore.store.password']
                keyAlias  = properties['keystore.key.alias']
                keyPass  = properties['keystore.key.password']
            }
            else
            {
                println "Getting keystore passwords from user input..."
                storePass = new String(System.console().readPassword("\nStore password: "))
                keyAlias  = new String(System.console().readLine("Key alias: "))
                keyPass  = new String(System.console().readPassword("Key password: "))
            }

            android.signingConfigs.release.storePassword = storePass
            android.signingConfigs.release.keyAlias = keyAlias
            android.signingConfigs.release.keyPassword = keyPass
        }


        tasks.whenTaskAdded
        {
            theTask ->
            if(theTask.name.equals("packageRelease"))
            {
                theTask.dependsOn "askForPasswords"
            }

4)当我跑步时,#gradlew assemble&#34;在终端,它说:没有找到评论。 为什么?什么是错?请帮帮我!

1 个答案:

答案 0 :(得分:1)

转到构建选项&gt;选择“生成签名的APK”

enter image description here