Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while compiling AIDL

I'm trying to compile .aidl and generate .java but:

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}

I use this 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'
}

And this root 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
}

I've read about issue with build tools, but I doesn't found anything about API 25

EDIT:

I've launched aidl.exe with params and it return:

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

EDIT 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();
}

This .aidl are located in src/main/aidl folder

like image 234
Michele Lacorte Avatar asked Dec 12 '16 21:12

Michele Lacorte


People also ask

What is AIDL in Android example?

The Android Interface Definition Language (AIDL) is a tool that lets users abstract away IPC. Given an interface (specified in a . aidl file), various build systems use the aidl binary to construct C++ or Java bindings so that this interface can be used across processes, regardless of the runtime or bitness there.

What is AIDL file?

An AIDL file is used by Android app developers to enable communication between different apps. It contains Java source code that defines an interface, or contract, for how apps can communicate with each other. AIDL is an implementation of the Interprocess Communication (IPC) protocol provided by Android.


3 Answers

Did you try to add verbose option to gradle or execute the same aidl.exe manually with the same parameters?

Probably there is an explanatory error code or message from aidl.exe that gradle does not show.

According to the error aidl can not open the file. Check if file exists there and the content is valid.

Try to change to the new default layout:

Put aidl files in /src/main/aidl

build.gradle:

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

(though, in general, if file is in /src/main/aidl it is supposed to work without aidl.srcDirs entry)

Don't forget that aidl files should be under package folders like java. For example, if the package is it.michelelacorte.testaidl, the aidl file should be under src/main/aidl/it/michelelacorte/testaidl.

In recent version of Android Studio, the New/AIDL/AIDL File project menu should already place the file under correct folder, if project package is set correctly.

like image 189
Fedor Losev Avatar answered Oct 01 '22 05:10

Fedor Losev


After refactoring java packages, the aidl files changed the packages structure also, but it missed the package in the file itself.

Assure that the aidl specifies the same package (first line in the .aidl) than the folder where it is.

like image 20
crgarridos Avatar answered Oct 01 '22 06:10

crgarridos


please add

import it.michelelacorte.androidshortcuts.Shortcuts;

in IRemoteShortcutService.aidl file.

like image 20
kingfeng Avatar answered Oct 01 '22 04:10

kingfeng