我的英语不好,我希望你能帮助我,谢谢大家
当前项目建立在android studio上,但我遇到了问题65536
我尝试使用google的multidex解决方案,编译没有任何问题,但运行时错误
此错误为Error caused by reflection
这是主要模块build.gradle
apply plugin: 'android'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':mycommons')
compile project(':PullToFreshLib')
compile project(':XMF')
compile project(':Iclap-Android-Eclipse-Library')
compile 'com.android.support:multidex:1.0.1'
}
//configurations {
// all*.exclude group: 'com.android.support', module: 'support-v4'
//}
android {
compileSdkVersion 19
buildToolsVersion '21.0.0'
dexOptions {
preDexLibraries = false
jumboMode = true
}
defaultConfig {
// applicationId "com.sht.smartcommunity"
// minSdkVersion 11
// targetSdkVersion 22
multiDexEnabled true
}
aaptOptions{
cruncherEnabled = false
useNewCruncher = false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
// afterEvaluate {
// tasks.matching {
// it.name.startsWith('dex')
// }.each { dx ->
// if (dx.additionalParameters == null) {
// dx.additionalParameters = []
// }
// dx.additionalParameters += '--multi-dex' // enable multidex
//
// // optional
// // dx.additionalParameters += "--main-dex-list=$projectDir/<filename>".toString() // enable the main-dex-list
// }
// }
}
我尝试回答堆栈溢出来解决看似别的失败,我不知道是什么导致了反射错误
这是ReqUestUtils.java的完整代码
package com.sht.smartcommunity.http;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import org.liushui.mycommons.android.log.McLog;
import org.liushui.mycommons.android.util.McToastUtil;
import android.text.TextUtils;
import com.sht.smartcommunity.AppApplication;
import com.sht.smartcommunity.R;
import com.sht.smartcommunity.annotation.ReqParam;
import com.sht.smartcommunity.annotation.RespText;
import com.sht.smartcommunity.annotation.SecurityType;
import com.sht.smartcommunity.http.request.BaseRequest;
import com.sht.smartcommunity.http.response.FailResponse;
import com.sht.smartcommunity.http.response.IJsonObj;
import com.sht.smartcommunity.http.response.JsonStrResponse;
import com.sht.smartcommunity.security.AppSecurityManager;
public class ReqRespUtils {
public static String[] makeGetUrl(BaseRequest request) {
List<KeyValue> params = request.getParams();
if (params == null) {
params = new ArrayList<KeyValue>();
}
Class<?> cls = request.getClass();
Field[] fs = cls.getFields();
for (Field f : fs) {
int modi = f.getModifiers();
if (Modifier.isStatic(modi)) {
continue;
}
//This is the wrong line 48
ReqParam reqParam = f.getAnnotation(ReqParam.class);
if (reqParam != null && !reqParam.asParam()) {
continue;
}
KeyValue kv = new KeyValue();
SecurityType type = SecurityType.None;
if (reqParam == null || TextUtils.isEmpty(reqParam.value())) {
kv.key = f.getName();
} else {
kv.key = reqParam.value();
}
if (reqParam != null) {
type = reqParam.security();
}
kv.securityType = type;
f.setAccessible(true);
try {
Object obj = f.get(request);
if (obj == null) {
if (reqParam != null) {
if (reqParam.required()) {
McLog.e(f.getName()
+ " is null,but it is required.");
kv.value = "";
params.add(kv);
} else {
// kv.value = "";
}
} else {
kv.value = null; // ?
params.add(kv);
}
} else {
kv.value = obj.toString();
params.add(kv);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
StringBuffer enSb = new StringBuffer();
StringBuffer normalSb = new StringBuffer();
boolean isFirst = true;
for (KeyValue kv : params) {
if (isFirst) {
isFirst = false;
} else {
enSb.append("&");
normalSb.append("&");
}
String v1 = encrpty(request, kv);
String v2 = TextUtils.isEmpty(kv.value) ? "" : kv.value;
enSb.append(kv.key + "=" + encode(v1));
normalSb.append(kv.key + "=" + encode(v2));
}
if (TextUtils.isEmpty(request.url)) {
McLog.w(request.getClass() + "'s url is empty, please check!!!");
}
String geturl1 = request.url + "?" + enSb.toString();
String geturl2 = request.url + "?" + normalSb.toString();
String[] res = new String[] { geturl1, geturl2 };
return res;
}
}
这是ReqParam.java的完整代码
package com.sht.smartcommunity.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ReqParam {
public String value() default "";
public boolean required() default false;
public boolean asParam() default true;
public SecurityType security() default SecurityType.None;
}