android开发笔记,杂

Mapping文件地址:

mapping文件用于在代码被混淆后,还原BUG信息。

release模式编译项目即可产生,相对位置:工程\build\outputs\mapping\release

 

需要clean project能解决的:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDevDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/ultrapower/mcs/engine/AudioCodecInfo.class

debug卡在waiting for debugger

解决方法:重启adb。

步骤:cmd进入命令行,进入adb所在目录先后执行adb kill-server,adb start-server。

 

获取APP版本号

 /**
     * 获取程序版本,参考build.gradle里面的versionName
     *
     * @param context
     * @return
     */
    public static String getVersionName(Context context) {
        PackageManager packageManager = context.getPackageManager();

        try {
            PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            return packInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            return "";
        }
    }

 

在桌面创建多个快捷方式

在指定的Activity的androidmanifest.xml加入LAUNCHER的category

 <intent-filter>
                <!--加入Launcher就可以了-->
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

 

No Application Debuggable

断点进不去,解决办法:

在gradle文件的debug和release属性下,加入

debuggable true

举例

 

去应用市场给apk打分

Uri uri = Uri.parse("market://details?id="+getPackageName());

Intent intent = new Intent(Intent.ACTION_VIEW,uri);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        
startActivity(intent);

 

自动在release模式下,混淆、压缩

打开app的build.gradle,参考下面代码进行修改

apply plugin: 'com.android.application'
//创建当前时间字符串 比如 0411_1213 表示 4月11号,12点13分
def buildTime() {
    def date = new Date()
    def formattedDate = date.format('MMdd_HHmm')
    return formattedDate
}
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    signingConfigs {
        release {
            keyAlias 'kimmy'
            keyPassword '123456'
            storeFile file('../test.jks')
            storePassword 'xl123456'
        }
    }
    defaultConfig {
        applicationId "com.zhexian.learn.myapplication"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 77
        versionName "1.0"
    }
    buildTypes {
        release {
            debuggable true
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release

            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    if (output.outputFile != null && output.outputFile.name.endsWith('.apk')
                            && 'release'.equals(variant.buildType.name)) {
                        String flavorName = variant.flavorName;
                        String versionName = variant.versionName;
                        String parentFile = output.outputFile.getParent();
                        if (flavorName != null && !flavorName.equals("")) {
                            output.outputFile = new File(parentFile, "${variant.buildType.name}_${flavorName}_v${versionName}_${buildTime()}.apk")
                        } else {
                            output.outputFile = new File(parentFile, "release_v${versionName}_${buildTime()}.apk")
                        }
                    }
                }
            }
        }
        debug {
            debuggable true
            jniDebuggable true
            minifyEnabled false
            shrinkResources false
            pseudoLocalesEnabled false
            signingConfig signingConfigs.release
        }
    }
}

 

posted @ 2015-09-17 13:29  谪仙  阅读(364)  评论(0编辑  收藏  举报