我有一个问题,Proguard剥离我的调试APK的方法(我需要在调试时运行proguard因为方法dex文件限制),即使它们在Test apk中使用.例如,我在单元测试中使用GSON addProeprty方法,但不在App apk中使用.这种方法被剥离并导致测试失败.但我不想将proguard配置为仅保留所有GSOn,因为dex文件限制,但也不希望单独列出所有方法.有没有办法告诉rpguard将单元测试视为源代码入口点?
在我们的项目中,我们经常处理列表,并在过去使用它并使用以下“模式”:
ListView 位于 Fragment 中,在 onActivityCreated 中初始化,我们首先启动 CursorLoaders,然后在 onFinish 中将 Cusor 交换到 ListAdapter。然后,我们使用 filterQueryProvider 实现了搜索功能,该功能仅通过 contentResolver.query(...) 返回游标。如果我在选择列表中的某些内容时进行了一些方向更改,则在许多情况下(不定期)会出现以下错误:
android.database.StaleDataException: Attempted to access a cursor after it has been closed.
12-05 10:36:59.531: E/ACRA(12079): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
12-05 10:36:59.531: E/ACRA(12079): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
12-05 10:36:59.531: E/ACRA(12079): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3378)
12-05 10:36:59.531: E/ACRA(12079): at android.app.ActivityThread.access$700(ActivityThread.java:127)
12-05 10:36:59.531: E/ACRA(12079): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1162)
12-05 10:36:59.531: E/ACRA(12079): at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 10:36:59.531: E/ACRA(12079): at android.os.Looper.loop(Looper.java:137)
12-05 10:36:59.531: E/ACRA(12079): at android.app.ActivityThread.main(ActivityThread.java:4448)
12-05 10:36:59.531: E/ACRA(12079): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 10:36:59.531: E/ACRA(12079): at java.lang.reflect.Method.invoke(Method.java:511)
12-05 …Run Code Online (Sandbox Code Playgroud) 我设置我的单元格如下:
因此,一些开关定义单元格,因为数据不在对象列表中,而是一组信息,应以某种不同的方式显示在tableView中.
-(UITableViewCell *)value1CellForTableView:(UITableView *)tableView {
static NSString *CellIdentifierValue1 = @"Value1Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierValue1];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifierValue1];
cell.detailTextLabel.textAlignment = UITextAlignmentLeft;
cell.textLabel.textAlignment = UITextAlignmentLeft;
}
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
switch (indexPath.section) {
case 0:
//Coupon
switch (indexPath.row) {
case 0:
//Couponcode
cell = [self value1CellForTableView:tableView];
cell.textLabel.text = @"Code";
cell.detailTextLabel.text = presentedCoupon.couponNr;
break;
case 1:
//Coupondescription
cell = [self value1CellForTableView:tableView];
cell.detailTextLabel.text = …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有:
-SplashScreen(SSc)准备应用程序(启动服务等)-MainActivity(MA)应用程序中最相关的部分,用于处理大多数操作-以及其他一些不相关的活动
对于我的应用程序,我希望具有类似launchMode singleTask的行为,以便即使通过链接打开我的应用程序,它也总是作为一个新任务启动,请在SMS / EMail应用程序中单击。最好是只有一个我的活动实例,因为它们都是可以连续导航的。
但是,当我以singleTask身份启动SSc时,它是堆栈的根并导航到MainActivity,按Home键,再次单击Launcher图标,应用程序将完全重新启动。因此,再次显示SSc,依此类推。在这种情况下,我希望将MainActivty放在首位。
我的愿望是:launcherclick-> SSc-> MA-> HOME-> launcherclick->将MA置于最前面-> HOME->从最近的站点重新启动->将MA置于最前面
单击具有相同实例的链接-> SSc / MA(是否首次启动)
在我的应用程序中,有多个实例是没有意义的,因为后台服务一次只能处理一个MainActivity,因为它仅针对可见的“事物”轮询数据。
您对实现这个目标有什么建议吗?
我的第一个想法是带有launchMode singletask的LauncherActivity,它没有布局以将意图路由到其他活动(最有可能是singleTop!?,因为它仅在一个任务中),例如:
public class LauncherActivity extends Activity {
private boolean firstStart = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
if(firstStart){
startActivity(new Intent(this, SplashScreen.class));
firstStart = false;
} else {
Intent i = new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
}
}
}
Run Code Online (Sandbox Code Playgroud)
清单xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="x.startintenttest">
<application
android:allowBackup="true"
android:allowTaskReparenting="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity …Run Code Online (Sandbox Code Playgroud) 我想使用ApplicationWrapepr方法在我的应用程序中使用multidex,如此处所述https://plus.google.com/104023661970539138053/posts/YTMf8ADTcFg
我使用了--minimal-main-dex选项以及这样的keep文件:
android/support/multidex/ZipUtil.class
android/support/multidex/ZipUtil$CentralDirectory.class
android/support/multidex/MultiDex$V14.class
android/support/multidex/MultiDexExtractor$1.class
android/support/multidex/MultiDexExtractor.class
com/<mypackage>/common/MyApplication.class
com/<mypackage>/common/MyApplicationWrapper.class
com/<mypackage>/common/ui/DashboardActivity.class
android/support/multidex/MultiDexApplication.class
android/support/multidex/MultiDex.class
android/support/multidex/MultiDex$V19.class
android/support/multidex/MultiDex$V4.class
Run Code Online (Sandbox Code Playgroud)
这导致我的主dex文件中列出的类是可以的.我使用一个使用以下代码的库来列出dexfile中的所有类,但只获取主"clesses.dex"的条目,而不是所有其他加载的dex文件的条目,因为新的DexFile只检查"classes.dex" :
private static List<String> getPaths(final String[] sourcePaths) {
List<String> result = new ArrayList<String>();
for (String s : sourcePaths) {
try {
DexFile dexfile = new DexFile(s);
Enumeration<String> entries = dexfile.entries();
while (entries.hasMoreElements()) {
result.add(entries.nextElement());
}
} catch (IOException ioe) {
Log.w(TAG, "cannot open file=" + s + ";Exception=" + ioe.getMessage());
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
现在的单一路径通过以下方式确定:
application.getApplicationContext().getApplicationInfo().sourceDir;
Run Code Online (Sandbox Code Playgroud)
结果像/data/../myapplicationname.apk
还有另一种可能性来列出dex文件中的所有类吗?或者目前在ClassLoaders中的所有课程?该库对项目至关重要,并使用此方法稍后通过反射查找组件实现.
EDIT1: 如果发现classes2.dex文件位于:/data/data/com./code_cache/secondary-dexes/com.-1.apk.classes2.dex
但是当使用带有此路径的新DexFile()时,将抛出IOEsxception,并显示消息"无法打开dexfile".
android ×4
classloader ×1
dex ×1
filter ×1
ios ×1
iphone ×1
launchmode ×1
list ×1
listview ×1
objective-c ×1
proguard ×1
uitableview ×1
unit-testing ×1