我正在使用android studio 2.3.2
开发应用,我也使用Jython
,因为我的应用中需要一个Python类。
我已经安装了Jython 2.7.0
并将其添加到path
我试图通过检查其他问题来解决我的问题:
这是我的代码:
接口SA
package com.aso.mdasa.mdasa;
interface SA {
Set resultCorpus(String DataBase, String polarity, String feature);
int resultSearch(String tweet);
}
Sentiment Analysis.java
class SentimentAnalysis {
private final Class interfaceType;
private final PyObject klass;
// Constructor obtains a reference to the importer, module, and the class name
private SentimentAnalysis(PySystemState state, Class interfaceType, String moduleName, String className) {
this.interfaceType = interfaceType;
PyObject importer = state.getBuiltins().__getitem__(Py.newString("__import__"));
PyObject module = importer.__call__(Py.newString(moduleName));
klass = module.__getattr__(className);
System.err.println("module=" + module + ",class=" + klass);
}
// This constructor passes through to the other constructor
public SentimentAnalysis(Class interfaceType, String moduleName, String className) {
this(new PySystemState(), interfaceType, moduleName, className);
}
// All of the followng methods return
// a coerced Jython object based upon the pieces of information
// that were passed into the SentimentAnalysis. The differences are
// between them are the number of arguments that can be passed
// in as arguents to the object.
public Object createObject() {
return klass.__call__().__tojava__(interfaceType);
}
public Object createObject(Object arg1) {
return klass.__call__(Py.java2py(arg1)).__tojava__(interfaceType);
}
Object createObject(Object arg1, Object arg2) {
return klass.__call__(Py.java2py(arg1), Py.java2py(arg2)).__tojava__(interfaceType);
}
public Object createObject(Object arg1, Object arg2, Object arg3)
{
return klass.__call__(Py.java2py(arg1), Py.java2py(arg2),
Py.java2py(arg3)).__tojava__(interfaceType);
}
private Object createObject(Object args[], String keywords[]) {
PyObject convertedArgs[] = new PyObject[args.length];
for (int i = 0; i < args.length; i++) {
convertedArgs[i] = Py.java2py(args[i]);
}
return klass.__call__(convertedArgs, keywords).__tojava__(interfaceType);
}
public Object createObject(Object... args) {
return createObject(args, Py.NoKeywords);
}
}
SAPython.py
from com.aso.mdasa.mdasa import SA
# Building object that subclasses a Java interface
from senticnet.senticnet import Senticnet
import pymysql
import pandas as pd
import sys
class SAPython (SA) :
__sn = Senticnet('ar')
def __init__(DBase) :
self.__connect(DBase)
def resultCorpus (self, polarity, feature = None):
result = {}
.....
return result
def resultSearch (self, tweet) :
return self.__calcTweetPolarity(tweet, len(tweet))
....
类ResultSearch
public class ResultSearch extends FragmentActivity{
private String search;
private ImageView img ;
public static final int[] photos = {
R.drawable.v_bad,
R.drawable.bad,
R.drawable.good,
R.drawable.v_good } ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result_search);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
public void onStart(){
super.onStart();
search = getIntent().getStringExtra("text");
img = (ImageView) findViewById(R.id.img);
sentimentAnalysis();
}
public void sentimentAnalysis() {
SentimentAnalysis sentimentA = new SentimentAnalysis(
SA.class, "SAPython", "SentimentAnalysis");
SA sa = (SA) sentimentA.createObject();
double result = sa.resultSearch(search);
if (result < -0.5)
img.setBackground(getResources().getDrawable(photos[0]));
if (result >= -0.5 && result < 0)
img.setBackground(getResources().getDrawable(photos[1]));
if (result >= 0 && result < 0.5)
img.setBackground(getResources().getDrawable(photos[2]));
if (result >= 0.5)
img.setBackground(getResources().getDrawable(photos[3]));
}
}
我收到此错误:
失败:构建因异常而失败。
出了什么问题:任务执行失败&#39;:app:transformClassesWithDexForDebug&#39;。 com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:返回dex的代码1 过程
尝试:使用--info或--debug选项运行以获取更多日志输出。
异常是:org.gradle.api.tasks.TaskExecutionException:任务&#39;:app:transformClassesWithDexForDebug&#39;执行失败。在 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84) 在 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55) 在 org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62) 在 org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) 在 org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88) 在 org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46) 在 org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51) 在 org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54) 在 org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 在 org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) 在 org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker $ 1.execute(DefaultTaskGraphExecuter.java:236) 在 org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker $ 1.execute(DefaultTaskGraphExecuter.java:228) 在 org.gradle.internal.Transformers $ 4.transform(Transformers.java:169) 在 org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106) 在 org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61) 在 org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228) 在 org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215) 在 org.gradle.execution.taskgraph.AbstractTaskPlanExecutor $ TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77) 在 org.gradle.execution.taskgraph.AbstractTaskPlanExecutor $ TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58) 在 org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32) 在 org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113) 在 org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37) 在 org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37) 在 org.gradle.execution.DefaultBuildExecuter.access $ 000(DefaultBuildExecuter.java:23) 在 org.gradle.execution.DefaultBuildExecuter $ 1.proceed(DefaultBuildExecuter.java:43) 在 org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) 在 org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37) 在 org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30) 在 org.gradle.initialization.DefaultGradleLauncher $ 3.execute(DefaultGradleLauncher.java:196) 在 org.gradle.initialization.DefaultGradleLauncher $ 3.execute(DefaultGradleLauncher.java:193) 在 org.gradle.internal.Transformers $ 4.transform(Transformers.java:169) 在 org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106) 在 org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56) 在 org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193) 在 org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119) 在 org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102) 在 org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71) 在 org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:50) 在 org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35) 在 org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner $ 1.execute(RunAsBuildOperationBuildActionRunner.java:43) 在 org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner $ 1.execute(RunAsBuildOperationBuildActionRunner.java:40) 在 org.gradle.internal.Transformers $ 4.transform(Transformers.java:169) 在 org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106) 在 org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56) 在 org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40) 在 org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:75) 在 org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35) 在 org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41) 在 org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26) 在 org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75) 在 org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49) 在 org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44) 在 org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29) 在 org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67) 在 org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36) 在 org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在 org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47) 在 org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在 org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26) 在 org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在 org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34) 在 org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在 org.gradle.launcher.daemon.server.exec.ForwardClientInput $ 2.call(ForwardClientInput.java:74) 在 org.gradle.launcher.daemon.server.exec.ForwardClientInput $ 2.call(ForwardClientInput.java:72) 在org.gradle.util.Swapper.swap(Swapper.java:38)at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72) 在 org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在 org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55) 在 org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在 org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60) 在 org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36) 在 org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在 org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72) 在 org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36) 在 org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 在 org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy $ 1.run(StartBuildOrRespondWithBusy.java:50) 在 org.gradle.launcher.daemon.server.DaemonStateCoordinator $ 1.run(DaemonStateCoordinator.java:297) 在 org.gradle.internal.concurrent.ExecutorPolicy $ CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54) 在 org.gradle.internal.concurrent.StoppableExecutorImpl $ 1.run(StoppableExecutorImpl.java:40) 引起:java.lang.RuntimeException: com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:返回dex的代码1 过程中 com.android.builder.profile.Recorder $ Block.handleException(Recorder.java:55) 在 com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104) 在 com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:176) 在org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73) 在 org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore $ IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:163) 在 org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore $ StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134) 在 org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore $ StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123) 在 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95) 在 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76) ... 78更多引起: com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:返回dex的代码1 过程中 com.android.build.gradle.internal.transforms.DexTransform.transform(DexTransform.java:453) 在 com.android.build.gradle.internal.pipeline.TransformTask $ 2.call(TransformTask.java:185) 在 com.android.build.gradle.internal.pipeline.TransformTask $ 2.call(TransformTask.java:181) 在 com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102) ... 85更多引起: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:返回dex的代码1 过程中 com.android.builder.core.DexByteCodeConverter.dexInProcess(DexByteCodeConverter.java:180) 在 com.android.builder.core.DexByteCodeConverter.runDexer(DexByteCodeConverter.java:158) 在 com.android.builder.core.DexByteCodeConverter.convertByteCode(DexByteCodeConverter.java:143) 在 com.android.builder.core.AndroidBuilder.convertByteCode(AndroidBuilder.java:1345) 在 com.android.build.gradle.internal.transforms.DexTransform.transform(DexTransform.java:279) ... 88更多引起:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:返回dex的代码1 过程中 com.android.builder.core.DexByteCodeConverter.dexInProcess(DexByteCodeConverter.java:178) ... 92更多引起: com.android.ide.common.process.ProcessException:返回dex的代码1 过程中 com.android.builder.internal.compiler.DexWrapper $ DexProcessResult.assertNormalExitValue(DexWrapper.java:117) 在 com.android.builder.core.DexByteCodeConverter.lambda $ $ dexInProcess 0(DexByteCodeConverter.java:175)
这是我的 gradle.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
dexOptions {
incremental true
preDexLibraries = false
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.aso.mdasa.mdasa"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling multidex support.
multiDexEnabled true
compileOptions.encoding = 'UTF8'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.7'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
compile files('libs/jython-standalone-2.7.0.jar')
}
和我的gradle.properties :
ject-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx4608M -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true