我正在尝试将AdColony集成到我的应用中,并且在我的调试版本上运行正常。但是,当我尝试构建发行版时,我遇到了ProGuard的问题,必须将其添加到proguard-rules-pro中才能使其正常工作:
-ignorewarnings
-keep class * {
public private *;
}
这是我完整的proguard-rules.pro:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field
-keepclassmembers class com.adcolony.sdk.ADCNative** {
*;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
-dontwarn com.squareup.**
-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
-ignorewarnings
-keep class * {
public private *;
}
现在,该广告无法在发行版或调试版中加载,因此我认为这是proguard的问题。如果现在从proguard中删除该代码,我也无法构建调试版本。这是我的广告代码:
public class AdcolonyAd extends AppCompatActivity {
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loading);
TextView loading = findViewById(R.id.loading_text);
loading.setText("Loading AdColony ...");
String app_id = getString(R.string.Adcolony_APP_ID);
String zone_id = getString(R.string.Adcolony_ZONE_ID);
String user = getAuth.user(this);
AdColonyAppOptions app_options = new AdColonyAppOptions().setUserID(user);
AdColony.configure(this, app_options, app_id, zone_id);
AdColonyAdOptions ad_options = new AdColonyAdOptions()
.enableConfirmationDialog(false)
.enableResultsDialog(false);
AdColonyInterstitialListener listener = new AdColonyInterstitialListener() {
@Override
public void onRequestFilled(AdColonyInterstitial ads) {
ads.show();
}
@Override
public void onRequestNotFilled(AdColonyZone zone) {
if (intent == null) {
AdcolonyAd.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(AdcolonyAd.this, getString(R.string.novideo), Toast.LENGTH_LONG).show();
}
});
} else {
startActivity(intent);
}
finish();
}
@Override
public void onOpened(AdColonyInterstitial ad) {
}
@Override
public void onClosed(AdColonyInterstitial ad) {
finish();
}
@Override
public void onExpiring(AdColonyInterstitial ad) {
finish();
}
};
AdColony.requestInterstitial(zone_id, listener, ad_options);
}
}
我总是收到onRequestNotFilled消息,因此我知道代码正在运行。这是我在logcat上找到的:
2018-12-01 12:43:51.714 9994-9994/? E/AdColony: JNI_OnLoad
2018-12-01 12:43:51.728 9994-10076/? I/AdColony [INFO]: Configuring AdColony
2018-12-01 12:43:53.692 9994-10076/? D/AdColony [TRACE]: Requesting AdColony interstitial advertisement.
这是在尝试创建内部版本而不修复proguard问题时出现的错误:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesAndResourcesWithProguardForDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Job failed, see logs for details
at com.android.build.gradle.internal.transforms.ProGuardTransform.transform(ProGuardTransform.java:207)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:239)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:235)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:230)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
... 33 more
Caused by: java.io.IOException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Stacks have different current sizes [0] and [1]
at com.android.build.gradle.internal.transforms.ProGuardTransform.doMinification(ProGuardTransform.java:268)
at com.android.build.gradle.internal.transforms.ProGuardTransform.access$000(ProGuardTransform.java:65)
at com.android.build.gradle.internal.transforms.ProGuardTransform$1.run(ProGuardTransform.java:176)
at com.android.builder.tasks.Job.runTask(Job.java:47)
at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:282)
... 1 more
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Stacks have different current sizes [0] and [1]
at proguard.classfile.visitor.ParallelAllClassVisitor.visitClassPool(ParallelAllClassVisitor.java:126)
at proguard.classfile.ClassPool.accept(ClassPool.java:110)
at proguard.optimize.Optimizer$TimedClassPoolVisitor.visitClassPool(Optimizer.java:1684)
at proguard.classfile.ClassPool.accept(ClassPool.java:110)
at proguard.optimize.Optimizer.execute(Optimizer.java:1392)
at proguard.ProGuard.optimize(ProGuard.java:413)
at proguard.ProGuard.execute(ProGuard.java:154)
at com.android.build.gradle.internal.transforms.BaseProguardAction.runProguard(BaseProguardAction.java:64)
at com.android.build.gradle.internal.transforms.ProGuardTransform.doMinification(ProGuardTransform.java:262)
... 6 more
Caused by: java.lang.IllegalArgumentException: Stacks have different current sizes [0] and [1]
at proguard.evaluation.Stack.generalize(Stack.java:125)
at proguard.evaluation.TracedStack.generalize(TracedStack.java:149)
at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:805)
at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:708)
at proguard.optimize.evaluation.PartialEvaluator.visitExceptionInfo(PartialEvaluator.java:1189)
at proguard.classfile.visitor.ExceptionHandlerFilter.visitExceptionInfo(ExceptionHandlerFilter.java:67)
at proguard.classfile.attribute.CodeAttribute.exceptionsAccept(CodeAttribute.java:226)
at proguard.optimize.evaluation.PartialEvaluator.evaluateExceptionHandlers(PartialEvaluator.java:1135)
at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.java:688)
at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute0(PartialEvaluator.java:317)
at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute(PartialEvaluator.java:230)
at proguard.optimize.evaluation.LivenessAnalyzer.visitCodeAttribute(LivenessAnalyzer.java:265)
at proguard.optimize.evaluation.VariableOptimizer.visitCodeAttribute(VariableOptimizer.java:105)
at proguard.optimize.info.OptimizationCodeAttributeFilter.visitCodeAttribute(OptimizationCodeAttributeFilter.java:84)
at proguard.classfile.attribute.visitor.DebugAttributeVisitor.visitCodeAttribute(DebugAttributeVisitor.java:302)
at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:141)
at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:101)
at proguard.classfile.attribute.visitor.AllAttributeVisitor.visitProgramMember(AllAttributeVisitor.java:95)
at proguard.classfile.util.SimplifiedVisitor.visitProgramMethod(SimplifiedVisitor.java:93)
at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:93)
at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:588)
at proguard.classfile.visitor.AllMethodVisitor.visitProgramClass(AllMethodVisitor.java:47)
at proguard.classfile.ProgramClass.accept(ProgramClass.java:430)
at proguard.classfile.visitor.ParallelAllClassVisitor$MyThreadedClassVisitor$1.run(ParallelAllClassVisitor.java:197)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
... 1 more
答案 0 :(得分:0)
我禁用了proguard,因为它给我带来的麻烦超出了应有的程度,并在adcolony配置上启用了测试广告。现在一切正常。