0

im currently stuck at using Object type for the AIDL.

SongItem.java

public class SongItem implements Parcelable{

}

SongItem.aidl

// SongItem.aidl
package com.example.krot.musicplayer;

// Declare any non-default types here with import statements
parcelable SongItem;

MyAIDL.aidl

 interface IPlaybackAction {

     void setSongList(in List<SongItem> item);
 }

Everytime i rebuild the project it keeps saying that

Error:aidl E 03-07 17:18:19 14651 1413571 type_namespace.cpp:129] unknown type

shadowsheep
  • 14,048
  • 3
  • 67
  • 77
Krot
  • 187
  • 3
  • 13
  • read this https://stackoverflow.com/questions/14263005/aidl-unable-to-find-the-definition-of-a-parcelable-class – Amir Mar 07 '18 at 10:51
  • @Amir: I do as the link guided but another bug appeared: In the generated class IPlaybackAction.java (when rebuild): cannot find symbol class SongItem public void setSongList(java.util.List item) throws android.os.RemoteException; – Krot Mar 07 '18 at 11:15
  • are all package name the same com.example.krot.musicplayer in all your classes. It seems either this or some variable you havent defined. – Amir Mar 07 '18 at 11:26
  • You really need to put more details like full java classes. – Amir Mar 07 '18 at 11:39
  • Yeah i have two packages: 1 in java folder and 1 in aidl folder and they have the same name com.example.krot.musicplayer – Krot Mar 07 '18 at 11:52

1 Answers1

3

The package for the SongItem class must match exactly between the Java and the AIDL, and the MyAIDL.aidl file must import the class (which is why you have the SongItem.aidl file which declares the class as parcelable.

Add this to the top of MyAIDL.aidl:

import com.example.krot.musicplayer.model.SongItem;

From the package structure image provided in the deleted answer, I can see SongItem.java is in a different package than what is in the AIDL. Move your SongItem.aidl file to be in the directory src/main/aidl/com/example/krot/musicplayer/model and update the package declaration at the top of that file to be com.example.krot.musicplayer.model.

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
  • I also did that, but still not working, still this error: public void setSongList(java.util.List item) throws android.os.RemoteException; It did not regconize SongItem – Krot Mar 07 '18 at 15:35
  • Please provide the exact build log – Larry Schiefer Mar 07 '18 at 17:38
  • 1. `Error:(363, 68) error: cannot find symbol class SongItem` . 2. `Error:(319, 78) error: cannot find symbol class SongItem` . 3. `Error:Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details` – Krot Mar 08 '18 at 01:58
  • Looks like something is off with the Java vs AIDL files. Could be package name, tree layout, etc. Can you make a list with a small project to illustrate the problem? – Larry Schiefer Mar 08 '18 at 03:36
  • I also created a new project, and the same bug still appeared. Do two packages (**1 in java folder, 1 in aidl folder**) must have the same name? In my current project is: `com.example.krot.musicplayer` – Krot Mar 08 '18 at 03:45
  • https://stackoverflow.com/questions/27138924/android-aidl-compile-error-couldnt-find-import-for-class/27408433 . <---- This is exactly the same issue with me, but i don't understand his verified answer – Krot Mar 08 '18 at 08:22
  • @Krot that other answer is for someone who is building their own custom service interface as part of the AOSP build, they are not using Android Studio. – Larry Schiefer Mar 08 '18 at 10:38
  • Can you post a gist of your new simpler project exhibiting the same problem? – Larry Schiefer Mar 08 '18 at 10:38
  • Just looked at the deleted additional data you originally posted which had the screen cap. Your `SongItem` java object is in a different package than the AIDL. It is in `com.example.krot.musicplayer.model`. I'll revise my answer above. – Larry Schiefer Mar 08 '18 at 10:41
  • 1
    Yeah you are absolutely right, i have to put either the **SongItem.aidl** and my **SongItem.java** in the same package. If i have my SongItem.java inside the package **com.example.krot.musicplayer.model** then i have to put my **SongItem.aidl** in the package **com.example.krot.musicplayer.model** (of course inside the aidl folder). Thank you so much, i solved my problem. – Krot Mar 08 '18 at 14:33