IOS构建失败,注释
问题描述:
我的IOS建立失败,如果i'm使用自定义的注释(很简单的一个)以下消息:IOS构建失败,注释
Error while working with the class: java/lang/annotation/Annotation file:com_we4it_aveedo_TestAnno no class definition
和从生成日志的标注类剪断:
/var/folders/zh/kb_4hqhn4kg1h0r5dp_6htcm0000gn/T/build5199219966381817658xxx/dist/MyApplication-src/com_we4it_aveedo_TestAnno.m:2:73: error: use of undeclared identifier 'class__java_lang_annotation_Annotation'; did you mean 'class__java_lang_InstantiationException'?
const struct clazz *base_interfaces_for_com_we4it_aveedo_TestAnno[] = {&class__java_lang_annotation_Annotation};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class__java_lang_InstantiationException
In file included from /var/folders/zh/kb_4hqhn4kg1h0r5dp_6htcm0000gn/T/build5199219966381817658xxx/dist/MyApplication-src/com_we4it_aveedo_TestAnno.m:1:
In file included from /var/folders/zh/kb_4hqhn4kg1h0r5dp_6htcm0000gn/T/build5199219966381817658xxx/dist/MyApplication-src/MyApplication-Prefix.pch:20:
In file included from /var/folders/zh/kb_4hqhn4kg1h0r5dp_6htcm0000gn/T/build5199219966381817658xxx/dist/MyApplication-src/java_lang_Class.h:8:
/var/folders/zh/kb_4hqhn4kg1h0r5dp_6htcm0000gn/T/build5199219966381817658xxx/dist/MyApplication-src/java_lang_InstantiationException.h:7:21: note: 'class__java_lang_InstantiationException' declared here
extern struct clazz class__java_lang_InstantiationException;
注释代码:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface TestAnno
{
public String kuchen();
}
在我的应用程序与下面的代码使用这就够了打破构建。
Class forName = Class.forName("justForTest");
TestAnno classNameAnnotation = (TestAnno) forName.getAnnotation(TestAnno.class);
问题是导致错误的第二行。 另一种方法,这也失败了,在下面的代码:
Class forName = Class.forName("justForTest");
Annotation[] annotation = forName.getAnnotations();
for (Annotation a : annotation)
{
if (a instanceof TestAnno)
{
TestAnno testAnno = (TestAnno) a;
}
}
让所有注释工作正常,但投放到我明确标注打破了那里建造。
是否有另一种方法来使用注释,或者它是一个错误,或者它甚至不支持IOS?
答
因为我们不支持反射支持运行时注解多大意义看不作:https://www.codenameone.com/blog/why-we-dont-support-the-full-java-api.html
由于移动应用是静态的,编译时间提前,这是不是真的有必要,也不会救你任何东西。
我知道,CN1不支持反射。这就是为什么许多方法不可用。但是可以使用一些方法,如Class.forName或getAnnotations。为什么将这些方法留在SDK中,如果它们没有实现并抛出错误? Class.forName肯定会起作用(如果您在Android上使用混淆名称)。只是因为移动应用程序是静态的并且编译并不意味着注释是无用的。这取决于你使用的是什么。在我们的例子中,我们将它们用于异常处理并提供其他信息 – Hatti
您如何知道类的混淆名称?我们添加这些方法的主要原因是允许Java 5代码进行编译,我同意如果它在API中但是对于特定目标失败则会出现问题,尽管我不确定是否正确的解决方案是将它们添加为iOS上的方法映射非常不同。 –
我们从具有混淆名称的异常中使用堆栈跟踪并使用它来加载类。 我知道一些东西非常复杂,无法移植到ios中。但如果它没有实施,应该更容易知道什么是错的。 (更好的消息在构建服务器上或至少javadoc这种方法) 我们花了几个小时来解决这个问题。特别是对于IOS这些日子的构建时间。 我们现在设法解决这个问题,因为我们只需要这些注释android – Hatti