编译AIDL

时间:2016-12-12 21:44:02

标签: java android android-studio build.gradle aidl

我尝试编译.aidl并生成.java,但是:

Error:Execution failed for task ':library:compileReleaseAidl'.
> java.lang.RuntimeException: com.android.ide.common.process.ProcessException:
Error while executing 'C:\Users\Michele\AppData\Local\Android\sdk\build-tools\25.0.0\aidl.exe'
with arguments {-pC:\Users\Michele\AppData\Local\Android\sdk\platforms\android-25\framework.aidl
-oC:\Users\Michele\workspace\AndroidLib\library\build\generated\source\aidl\release
-IC:\Users\Michele\workspace\AndroidLib\library\src
-IC:\Users\Michele\workspace\AndroidLib\library\src\release\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\appcompat-v7\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-v4\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-fragment\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-media-compat\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-core-ui\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-core-utils\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\animated-vector-drawable\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-vector-drawable\25.0.1\aidl
-IC:\Users\Michele\workspace\AndroidLib\library\build\intermediates\exploded-aar\com.android.support\support-compat\25.0.1\aidl
-dC:\Users\Michele\AppData\Local\Temp\aidl3070615992051288022.d
C:\Users\Michele\workspace\AndroidLib\library\src\IRemoteShortcutService.aidl}

我使用此build.gradle

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.michelelacorte'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 2
        versionName "0.2.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    sourceSets {
        main {
            aidl.srcDirs = ['src/main/aidl']
        }
    }

    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.0.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.code.gson:gson:2.8.0'
}

这个根build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我已经阅读过有关构建工具的问题,但我找不到有关API 25的任何内容

修改

我已经使用参数启动aidl.exe并返回:

aidl.exe E  2236 13884 aidl_language.cpp:224] Error while opening file for parsing: 'C:\Users\Michele\workspace\AndroidLib\library\src\IRemoteShortcutService.aidl'

编辑2:

Shortcut.aidl

// Shortcut.aidl
package it.michelelacorte.androidshortcuts;

parcelable Shortcuts;

IRemoteShortcutService.aidl

// IRemoteShortcutService.aidl
package it.michelelacorte.androidshortcuts;

interface IRemoteShortcutService {

    void addShortcuts(int shortcutsImage, String shortcutsText);

    Shortcuts getShortcuts();
}

.aidl位于src/main/aidl文件夹

4 个答案:

答案 0 :(得分:6)

您是否尝试将grabose选项添加到gradle或使用相同的参数手动执行相同的aidl.exe?

可能有一个解释性错误代码或来自aidl.exe的消息,gradle没有显示。

根据错误,aidl无法打开文件。检查文件是否存在且内容有效。

尝试更改为新的默认布局:

将aidl文件放入/src/main/aidl

的build.gradle:

...
    sourceSets {
        main {
            aidl.srcDirs = ['src/main/aidl']
        }
    }

(但是,一般来说,如果文件在/src/main/aidl中,它应该在没有aidl.srcDirs条目的情况下工作)

不要忘记aidl文件应该在java等包文件夹下。例如,如果包是it.michelelacorte.testaidl,则aidl文件应位于src/main/aidl/it/michelelacorte/testaidl下。

在Android Studio的最新版本中,如果项目包设置正确,New/AIDL/AIDL File项目菜单应该已将文件放在正确的文件夹下。

答案 1 :(得分:3)

重构java包之后,aidl文件也改变了包结构,但它错过了文件本身的包。

确保aidl指定相同的包(.aidl中的第一行)而不是文件夹。

答案 2 :(得分:2)

请添加

import it.michelelacorte.androidshortcuts.Shortcuts;

IRemoteShortcutService.aidl档案中。

答案 3 :(得分:0)

我的版本与你的版本相同。

我只是尝试编辑IRemoteShortcutService.aidl以导入快捷方式类。

虽然它们在同一个包中,但它可以成功编译。