我正在尝试为appinventor构建扩展名,但是当我执行ant extensions
时,我会得到此错误:
[Javac]注释处理器抛出了一个未知的例外。
[Javac]请咨询以下堆栈跟踪以获取详细信息。
[javac] java.lang.runtimeException:无法将java type'android.content.context'转换为yail类型
完整错误日志:
[javac]
[javac] An annotation processor threw an uncaught exception.
[javac] Consult the following stack trace for details.
[javac] java.lang.RuntimeException: Cannot convert Java type 'android.content.Context' to Yail type
[javac] at com.google.appinventor.components.scripts.ComponentProcessor.javaTypeToYailType(ComponentProcessor.ja
va:1184)
[javac] at com.google.appinventor.components.scripts.ComponentDescriptorGenerator.outputParameters(ComponentDesc
riptorGenerator.java:208)
[javac] at com.google.appinventor.components.scripts.ComponentDescriptorGenerator.outputBlockMethod(ComponentDes
criptorGenerator.java:187)
[javac] at com.google.appinventor.components.scripts.ComponentDescriptorGenerator.outputComponent(ComponentDescr
iptorGenerator.java:125)
[javac] at com.google.appinventor.components.scripts.ComponentDescriptorGenerator.outputResults(ComponentDescrip
torGenerator.java:226)
[javac] at com.google.appinventor.components.scripts.ComponentProcessor.process(ComponentProcessor.java:731)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.ja
va:794)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironm
ent.java:705)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java
:91)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1
035)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.jav
a:1176)
[javac] at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
[javac] at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:523)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:381)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:370)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:361)
[javac] at com.sun.tools.javac.Main.compile(Main.java:56)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:58)
[javac] at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1395)
[javac] at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:1121)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:402)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.Target.execute(Target.java:435)
[javac] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[javac] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
[javac] at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
[javac] at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
[javac] at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.Target.execute(Target.java:435)
[javac] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[javac] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
[javac] at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
[javac] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[javac] at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
[javac] at org.apache.tools.ant.Main.runBuild(Main.java:857)
[javac] at org.apache.tools.ant.Main.startAnt(Main.java:236)
[javac] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:287)
[javac] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:113)
BUILD FAILED
D:appinventor-sourcesappinventorbuild.xml:37: The following error occurred while executing this line:
D:appinventor-sourcesappinventorcomponentsbuild.xml:343: The following error occurred while executing this line:
D:appinventor-sourcesappinventorcomponentsbuild.xml:230: Compile failed; see the compiler error output for details.
可以在此处找到引起此错误的文件:
https://github.com/barreeeiroo/appinventor-sources/blob/master/master/appinventor/components/src/src/com/google/google/appinventor/appinventor/components/runtime/runtime/versionname.java
我认为这条线是: import android.content.Context;
在第24行
当我构建扩展程序时,该文件上没有错误,例如导入该库时是错误,因为我尝试了import android.content.pm.Context
,但是它在读取文件时会崩溃,所以我想这是Javac或Java错误
我该如何解决?
通常您会得到这样的上下文
public class TaifunTools extends AndroidNonvisibleComponent {
private static Context context;
private static final String LOG_TAG = "TaifunTools";
public TaifunTools(ComponentContainer container) {
super(container.$form());
this.container = container;
context = (Context) container.$context();
}
所以稍后您将使用此片段获取版本名称
@SimpleFunction(description = "Returns the version name of the app")
public String VersionName() {
Log.d(LOG_TAG, "VersionName");
try {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
String version = pInfo.versionName;
return version;
} catch (NameNotFoundException e) {
Log.e(LOG_TAG, e.getMessage());
e.printStackTrace();
return "";
}
}
顺便说一句。有关与应用程序发明家来源合作的问题,最好的地方是在应用程序发明家开源论坛中询问...
另请参见App Inventor扩展文档,并研究MIT提供的示例扩展。