我有一个疑问。我们可以在aidl文件中声明一个常量变量吗? 例如,我有一个名为ITest.aidl的援助文件:
package com.example.test;
interface ITest {
public static final String name = "abc";
public static final int number = 1234;
}
当我尝试我的测试应用程序时,它会出现语法错误和运行时异常
Error:(4) syntax error
Error:(4) syntax error before ';' (expected method or constant declaration)
Error:(5) syntax error
Error:Execution failed for task ':app:compileDebugAidl'.
java.lang.RuntimeException: com.android.ide.common.process.ProcessException: Error while executing 'D:\Android\sdk\build-tools\25.0.2\aidl.exe' with arguments {-pD:\Android\sdk\platforms\android-25\framework.aidl -oE:\Workspace-Production\MyTestingApplication\app\build\generated\source\aidl\debug -IE:\Workspace-Production\MyTestingApplication\app\src\main\aidl -IE:\Workspace-Production\MyTestingApplication\app\src\debug\aidl -IE:\Workspace-Production\MyTestingApplication\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\25.1.1\aidl -IE:\Workspace-Production\MyTestingApplication\app\build\intermediates\exploded-aar\com.android.support\support-v4\25.1.1\aidl -IE:\Workspace-Production\MyTestingApplication\app\build\intermediates\exploded-aar\com.android.support\support-fragment\25.1.1\aidl -IE:\Workspace-Production\MyTestingApplication\app\build\intermediates\exploded-aar\com.android.support\support-media-compat\25.1.1\aidl -IE:\Workspace-Production\MyTestingApplication\app\build\intermediates\exploded-aar\com.android.support\support-core-ui\25.1.1\aidl -IE:\Workspace-Production\MyTestingApplication\app\build\intermediates\exploded-aar\com.android.support\support-core-utils\25.1.1\aidl -IE:\Workspace-Production\MyTestingApplication\app\build\intermediates\exploded-aar\com.android.support\animated-vector-drawable\25.1.1\aidl -IE:\Workspace-Production\MyTestingApplication\app\build\intermediates\exploded-aar\com.android.support\support-vector-drawable\25.1.1\aidl -IE:\Workspace-Production\MyTestingApplication\app\build\intermediates\exploded-aar\com.android.support\support-compat\25.1.1\aidl -dC:\Users\20065920\AppData\Local\Temp\aidl2875180729857776911.d E:\Workspace-Production\MyTestingApplication\app\src\main\aidl\ITest.aidl
请向我推荐一些链接,为什么它会像这样?
答案 0 :(得分:2)
AIDL支持方法和常量声明。
您必须通过以下方式在aidl接口上更新常量声明:
package com.example.test;
interface ITest {
public static final String name = "abc";
public static final int number = 1234;
}
到
package com.example.test;
interface ITest {
const String NAME = "abc";
const int NUMBER= 1234;
}
可以在AIDL接口中定义字符串和int常量。 例如:const int VERSION = 1;
答案 1 :(得分:1)
您可以使用 const int number =“ 1234”