我使用“断言”;我的应用程序中的code关键字,当运行apk时,在android studio中通过APG版本打包时不起作用
开发环境如下:
androidStudio:4.2.2:
包装gradle:https://services.gradle.org/distributions/gradle-4.10.1-bin.zip:
android Gradle 插件:'com.android.tools.build:gradle:3.2.0':
我简单地创建测试代码:
package com.example.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
testAssert();
}
private void testAssert() {
assert Looper.myLooper()!=Looper.getMainLooper();
Log.i("yich","pass!!!!!!!!!");
}
}
android gradle 配置如下:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 29
// buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
}
当我通过 android studio 运行此代码时,应用程序工作正常,'assert' 关键字代码不起作用,所以我反编译 apk,我发现我的 apk 中没有 'assert' 代码,下图:反编译代码截图,
我猜可能是AGP在将代码打包到apk时的bug,当将MainActivity.class编译为dex文件时,断言代码在class文件中,但我发现断言代码在dex文件中丢失,那么我做错了什么,使打包APk时断言代码丢失?需要一些帮助!
dev env is below:
androidStudio :4.2.2:
wrap gradle:https://services.gradle.org/distributions/gradle-4.10.1-bin.zip:
android Gradle plugin:'com.android.tools.build:gradle:3.2.0':
and i simplely create test code:
package com.example.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
testAssert();
}
private void testAssert() {
assert Looper.myLooper()!=Looper.getMainLooper();
Log.i("yich","pass!!!!!!!!!");
}
}
android gradle config is below:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 29
// buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
}
when I run this code by android studio, app work fine, the 'assert' keywrod code not work,so i decompile apk i found no 'assert' code in my apk,pic below:decompile code screenshot ,
i guess it may be AGP's bug when package code into apk,when compile MainActivity.class to dex file ,the assert code is in class file,but i found that assert code lose in dex file,so what i do wrong to make assert code lose when packaging APk? need some help!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论