gpt4 book ai didi

java - 反射不适用于 android 版本 apk。即使禁用了 proguard/minify

转载 作者:行者123 更新时间:2023-11-29 19:25:15 30 4
gpt4 key购买 nike

目前我面临一个奇怪的问题,即我的应用程序的发布 apk 抛出 NoSuchFieldExceptions。它在调试 apk 上运行良好。

我要获取的字段是android.widget打包的。我也努力启用混淆器并在 proguard.pro 文件中设置配置

这里是异常(exception)情况。

java.lang.IllegalAccessException:类 java.lang.Class 无法访问类 java.lang.Class 的字段 android.widget.ProgressBar com.trinitcore.localtrade.LoginActivity.o

Gradle 文件

    apply plugin: 'com.android.application'

android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.trinitcore.localtrade"
minSdkVersion 15 //15
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.7
sourceCompatibility 1.7
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile('com.mikepenz:materialdrawer:5.4.0@aar') {
transitive = true
}
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:design:+'
compile 'com.quinny898.library.persistentsearch:library:1.1.0-SNAPSHOT'
compile 'com.github.paolorotolo:appintro:4.0.0'
compile 'com.mikepenz:materialize:0.9.0@aar'
compile 'com.mikepenz:iconics-core:2.7.2@aar'
compile 'com.mikepenz:fastadapter:1.6.1@aar'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.android.gms:play-services:9.6.0'
compile 'com.android.support:support-v4:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile "com.mikepenz:iconics-core:2.8.1@aar"
compile 'com.mikepenz:google-material-typeface:2.2.0.3.original@aar'
compile 'com.mikepenz:material-design-iconic-typeface:2.2.0.2@aar'
compile 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar'
compile 'com.mikepenz:octicons-typeface:3.2.0.2@aar'
compile 'com.mikepenz:meteocons-typeface:1.1.0.2@aar'
compile 'com.mikepenz:community-material-typeface:1.7.22.1@aar'
compile 'com.mikepenz:weather-icons-typeface:2.0.10.2@aar'
compile 'com.mikepenz:typeicons-typeface:2.0.7.2@aar'
compile 'com.mikepenz:entypo-typeface:1.0.0.2@aar'
compile 'com.mikepenz:devicon-typeface:2.0.0.2@aar'
compile 'com.mikepenz:foundation-icons-typeface:3.0.0.2@aar'
compile 'com.mikepenz:ionicons-typeface:2.0.1.2@aar'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.lusfold.spinnerloading:library:1.0.0'
compile 'com.github.medyo:fancybuttons:1.8.3'
compile 'jp.wasabeef:blurry:2.1.0'
compile ('org.apache.httpcomponents:httpmime:4.3'){
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
compile ('org.apache.httpcomponents:httpcore:4.4.1'){
exclude group: 'org.apache.httpcomponents', module: 'httpclient'

}
testCompile 'junit:junit:4.12'
}

最佳答案

IllegalAccessException 意味着它可以看到变量/方法,但它不能访问它,因为它是私有(private)的(或者因为它是 protected ,并且这不是同一个包)。这不是反射不起作用的情况,这是一个没有反射就无法编译的常见错误。

您可以使用反射在运行时更改变量/方法的可见性,然后访问它,但不推荐这样做。最好添加一个公共(public)方法来执行您需要的操作,以防止以类未编写为接受的方式更改数据的可能性。

关于java - 反射不适用于 android 版本 apk。即使禁用了 proguard/minify,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41525867/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com