AIDL file does not generated a Java file - android

I have defined an AIDL android interface to make available a service from other applications.
My problem is that in my project, Android does not generate the Java file from this AIDL.
Note that the project compiles and works fine. However, if I move this AIDL file to another project, Android generates the Java file.
I don't know where I can debug this kind of error or where I can read some log about this.
Can anybody help me?

I met the same issue and work fine for me on Android Studio. There are two ways to fix this.
Method 1:
Put AIDL files under src/main/aidl package to follow default source setting for gradle build.
It is easy way but not be smart.
Method 2:
Keep aidl files under your custom package.
Add source setting mapping in build.gradle file as below
sourceSets {
main {
aidl.srcDirs = ['src/main/java']
}
}
Don't forget clean and rebuild after setting as above.
More information please refer this,
https://issuetracker.google.com/issues/36972230
https://issuetracker.google.com/issues/36972230
https://issuetracker.google.com/issues/36988483

I ran into a similar issue. Using Android Studio, the file is required to be in a specific location unless you override it in Gradle.
I had to put the aidl file in 'src/main/aidl/example/package/name/' <-- The declared package in the aidl file would be 'package example.package.name'.
It requires the file to be in a specific aidl folder and to have a folder structure that matches the package name declared in the aidl. I found the initial hint here: https://code.google.com/p/android/issues/detail?id=56328

Eclipse displays you the errors directly in the .aidl file, so check your file first.
I got similar issue, and found my problem: I prefixed my interface functions with public. That was wrong. For instance:
package com.example.phone.service;
interface IService {
public void placeCall(String a, in String b, in String c);
}
should be:
package com.example.phone.service;
interface IService {
void placeCall(String a, in String b, in String c);
}
Don't forget the .java generated file is located in gen/ not src/.

Try cleaning the project, that's often helping to resolve those types of errors. Also check that it does not contain errors since errors can prevent completion of some compile steps.
Assuming you use Eclipse have a look at the "Console" view (Window > Show View > Console) which should contain the output of the compile process.

if you go to one of the parent directories depending on where you trying to create the interface e.g framework/base/ you will find the make file of this dir called Android.mk
in this file you should add the .aidl name in the proper spots (it is easy to understand exactly where thanks to the comments) and then build. the "your interface".java will be generated.

Related

What is this problem and what is its solution, Please Help me [duplicate]

I'm getting a NoSuchMethodError error when running my Java program. What's wrong and how do I fix it?
Without any more information it is difficult to pinpoint the problem, but the root cause is that you most likely have compiled a class against a different version of the class that is missing a method, than the one you are using when running it.
Look at the stack trace ... If the exception appears when calling a method on an object in a library, you are most likely using separate versions of the library when compiling and running. Make sure you have the right version both places.
If the exception appears when calling a method on objects instantiated by classes you made, then your build process seems to be faulty. Make sure the class files that you are actually running are updated when you compile.
I was having your problem, and this is how I fixed it. The following steps are a working way to add a library. I had done the first two steps right, but I hadn't done the last one by dragging the ".jar" file direct from the file system into the "lib" folder on my eclipse project. Additionally, I had to remove the previous version of the library from both the build path and the "lib" folder.
Step 1 - Add .jar to build path
Step 2 - Associate sources and javadocs (optional)
Step 3 - Actually drag .jar file into "lib" folder (not optional)
Note that in the case of reflection, you get an NoSuchMethodException, while with non-reflective code, you get NoSuchMethodError. I tend to go looking in very different places when confronted with one versus the other.
If you have access to change the JVM parameters, adding verbose output should allow you to see what classes are being loaded from which JAR files.
java -verbose:class <other args>
When your program is run, the JVM should dump to standard out information such as:
...
[Loaded junit.framework.Assert from file:/C:/Program%20Files/junit3.8.2/junit.jar]
...
If using Maven or another framework, and you get this error almost randomly, try a clean install like...
clean install
This is especially likely to work if you wrote the object and you know it has the method.
This is usually caused when using a build system like Apache Ant that only compiles java files when the java file is newer than the class file. If a method signature changes and classes were using the old version things may not be compiled correctly. The usual fix is to do a full rebuild (usually "ant clean" then "ant").
Sometimes this can also be caused when compiling against one version of a library but running against a different version.
I had the same error:
Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonGenerator.writeStartObject(Ljava/lang/Object;)V
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:151)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3681)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3057)
To solve it I checked, firstly, Module Dependency Diagram (click in your POM the combination -> Ctrl+Alt+Shift+U or right click in your POM -> Maven -> Show dependencies) to understand where exactly was the conflict between libraries (Intelij IDEA). In my particular case, I had different versions of Jackson dependencies.
1) So, I added directly in my POM of the project explicitly the highest version - 2.8.7 of these two.
In properties:
<jackson.version>2.8.7</jackson.version>
And as dependency:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
2) But also it can be solved using Dependency Exclusions.
By the same principle as below in example:
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-a</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
Dependency with unwanted version will be excluded from your project.
This can also be the result of using reflection. If you have code that reflects on a class and extracts a method by name (eg: with Class.getDeclaredMethod("someMethodName", .....)) then any time that method name changes, such as during a refactor, you will need to remember to update the parameters to the reflection method to match the new method signature, or the getDeclaredMethod call will throw a NoSuchMethodException.
If this is the reason, then the stack trace should show the point that the reflection method is invoked, and you'll just need to update the parameters to match the actual method signature.
In my experience, this comes up occasionally when unit testing private methods/fields, and using a TestUtilities class to extract fields for test verification. (Generally with legacy code that wasn't designed with unit testing in mind.)
If you are writing a webapp, ensure that you don't have conflicting versions of a jar in your container's global library directory and also in your app. You may not necessarily know which jar is being used by the classloader.
e.g.
tomcat/common/lib
mywebapp/WEB-INF/lib
For me it happened because I changed argument type in function, from Object a, to String a. I could resolve it with clean and build again
In my case I had a multi module project and scenario was like com.xyz.TestClass was in module A and as well as in module B and module A was dependent on module B. So while creating a assembly jar I think only one version of class was retained if that doesn't have the invoked method then I was getting NoSuchMethodError runtime exception, but compilation was fine.
Related : https://reflectoring.io/nosuchmethod/
Why anybody doesn't mention dependency conflicts? This common problem can be related to included dependency jars with different versions.
Detailed explanation and solution: https://dzone.com/articles/solving-dependency-conflicts-in-maven
Short answer;
Add this maven dependency;
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<rules>
<dependencyConvergence />
</rules>
</configuration>
</plugin>
Then run this command;
mvn enforcer:enforce
Maybe this is the cause your the issue you faced.
It means the respective method is not present in the class:
If you are using jar then decompile and check if the respective version of jar have proper class.
Check if you have compiled proper class from your source.
I have just solved this error by restarting my Eclipse and run the applcation.
The reason for my case may because I replace my source files without closing my project or Eclipse.
Which caused different version of classes I was using.
Try this way: remove all .class files under your project directories (and, of course, all subdirectories). Rebuild.
Sometimes mvn clean (if you are using maven) does not clean .class files manually created by javac. And those old files contain old signatures, leading to NoSuchMethodError.
Just adding to existing answers. I was facing this issue with tomcat in eclipse. I had changed one class and did following steps,
Cleaned and built the project in eclpise
mvn clean install
Restarted tomcat
Still I was facing same error. Then I cleaned tomcat, cleaned tomcat working directory and restarted server and my issue is gone. Hope this helps someone
These problems are caused by the use of the same object at the same two classes.
Objects used does not contain new method has been added that the new object class contains.
ex:
filenotnull=/DayMoreConfig.conf
16-07-2015 05:02:10:ussdgw-1: Open TCP/IP connection to SMSC: 10.149.96.66 at 2775
16-07-2015 05:02:10:ussdgw-1: Bind request: (bindreq: (pdu: 0 9 0 [1]) 900 900 GEN 52 (addrrang: 0 0 2000) )
Exception in thread "main" java.lang.NoSuchMethodError: gateway.smpp.PDUEventListener.<init>(Lgateway/smpp/USSDClient;)V
at gateway.smpp.USSDClient.bind(USSDClient.java:139)
at gateway.USSDGW.initSmppConnection(USSDGW.java:274)
at gateway.USSDGW.<init>(USSDGW.java:184)
at com.vinaphone.app.ttn.USSDDayMore.main(USSDDayMore.java:40)
-bash-3.00$
These problems are caused by the concomitant 02 similar class (1 in src, 1 in jar file here is gateway.jar)
To answer the original question. According to java docs here:
"NoSuchMethodError" Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
If it happens in the run time, check the class containing the method is in class path.
Check if you have added new version of JAR and the method is compatible.
I fixed this problem in Eclipse by renaming a Junit test file.
In my Eclipse work space I have an App project and a Test project.
The Test project has the App project as a required project on the build path.
Started getting the NoSuchMethodError.
Then I realized the class in the Test project had the same name as the class in the App project.
App/
src/
com.example/
Projection.java
Test/
src/
com.example/
Projection.java
After renaming the Test to the correct name "ProjectionTest.java" the exception went away.
NoSuchMethodError : I have spend couple of hours fixing this issue, finally fixed it by just renaming package name , clean and build ... Try clean build first if it doesn't works try renaming the class name or package name and clean build...it should be fixed. Good luck.
I ran into a similar problem when I was changing method signatures in my application.
Cleaning and rebuilding my project resolved the "NoSuchMethodError".
Above answer explains very well ..just to add one thing
If you are using using eclipse use ctrl+shift+T and enter package structure of class (e.g. : gateway.smpp.PDUEventListener ), you will find all jars/projects where it's present. Remove unnecessary jars from classpath or add above in class path. Now it will pick up correct one.
I ran into similar issue.
Caused by: java.lang.NoSuchMethodError: com.abc.Employee.getEmpId()I
Finally I identified the root cause was changing the data type of variable.
Employee.java --> Contains the variable (EmpId) whose Data Type has been changed from int to String.
ReportGeneration.java --> Retrieves the value using the getter, getEmpId().
We are supposed to rebundle the jar by including only the modified classes. As there was no change in ReportGeneration.java I was only including the Employee.class in Jar file. I had to include the ReportGeneration.class file in the jar to solve the issue.
I've had the same problem. This is also caused when there is an ambiguity in classes. My program was trying to invoke a method which was present in two JAR files present in the same location / class path. Delete one JAR file or execute your code such that only one JAR file is used. Check that you are not using same JAR or different versions of the same JAR that contain the same class.
DISP_E_EXCEPTION [step] [] [Z-JAVA-105 Java exception java.lang.NoSuchMethodError(com.example.yourmethod)]
Most of the times java.lang.NoSuchMethodError is caught be compiler but sometimes it can occur at runtime. If this error occurs at runtime then the only reason could be the change in the class structure that made it incompatible.
Best Explanation: https://www.journaldev.com/14538/java-lang-nosuchmethoderror
I've encountered this error too.
My problem was that I've changed a method's signature, something like
void invest(Currency money){...}
into
void invest(Euro money){...}
This method was invoked from a context similar to
public static void main(String args[]) {
Bank myBank = new Bank();
Euro capital = new Euro();
myBank.invest(capital);
}
The compiler was silent with regard to warnings/ errors, as capital is both Currency as well as Euro.
The problem appeared due to the fact that I only compiled the class in which the method was defined - Bank, but not the class from which the method is being called from, which contains the main() method.
This issue is not something you might encounter too often, as most frequently the project is rebuilt mannually or a Build action is triggered automatically, instead of just compiling the one modified class.
My usecase was that I generated a .jar file which was to be used as a hotfix, that did not contain the App.class as this was not modified. It made sense to me not to include it as I kept the initial argument's base class trough inheritance.
The thing is, when you compile a class, the resulting bytecode is kind of static, in other words, it's a hard-reference.
The original disassembled bytecode (generated with the javap tool) looks like this:
#7 = Methodref #2.#22 // Bank.invest:(LCurrency;)V
After the ClassLoader loads the new compiled Bank.class, it will not find such a method, it appears as if it was removed and not changed, thus the named error.
Hope this helps.
The problem in my case was having two versions of the same library in the build path. The older version of the library didn't have the function, and newer one did.
I had a similar problem with my Gradle Project using Intelij.
I solved it by deleting the .gradle (see screenshot below) Package and rebuilding the Project.
.gradle Package
I had faced the same issue. I changed the return type of one method and ran the test code of that one class. That is when I faced this NoSuchMethodError. As a solution, I ran the maven builds on the entire repository once, before running the test code again. The issue got resolved in the next single test run.
One such instance where this error occurs:
I happened to make a silly mistake of accessing private static member variables in a non static method. Changing the method to static solved the problem.

Change Package Name after implementation of data binding

I'm using Databinding with one of my project with project name com.abc.def. I've related all my views with binding like
ActivityLoginBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_login);
it worked fine but if I change my package name to com.Abc.Def it generated following error at the time of building Apk.
Cause: couldn't make a guess for
com.Abc.Def.databinding.ActivityLoginBindingImpl .
Please Note:
I have an old build with com.Abc.Def on playstore already live and I'm updating the version. That's why I have to Change package name.
I can't remove Databinding from whole project.as it relates to all views.
If I change my package name to old one ,it works fine.
I have already tried clean , rebuild and invalidate cache and restart .but no luck.
I just bumped into the same issue. I was able to fix it by toggling databinding.enabled inside Build.gradle (Module). Below is a little step-by-step guide, that I went through after renaming my company package (com.abc.myapp -> com.xyz.myapp), which got databinding to work as expected:
Build > Clean Project
go to your Build.gradle (Module) and disable databinding:
android {
dataBinding {
enabled = false
}
}
File > Sync Project with Gradle Files
Build > Rebuild Project (no surprise: you'll get a ton of error messages)
Now enable databinding again:
android {
dataBinding {
enabled = true
}
}
File > Sync Project with Gradle Files
Build > Rebuild Project
Note: Some steps here may be unnecessary, but a little extra sanity checking has never done any harm during project setup, right!?
According to JAVA package naming conventions:
The package name may contain uppercase or lowercase letters[a-z], numbers, and underscores [ _ ].
You can not use capital letters in naming packages.
com..Abc.Def.databinding.ActivityLoginBindingImpl .
Check if there is no empty package there, for those ..
first of all, did you changed package name only in Manifest?
note that it could be different to applicationId - so you can only change it and leave app package as it was.
RCA: probably OS you are using to build is case-insensitive but java compiler is - that's reason why it can't find classes. Bindings are generated alongside other generated classes (for example dagger 2 classes generated by annotation processor), each generator creates own files within folder structure that reflects class package BUT if packages differ only with big/small letters, second generator will use same folder with wrong name. The reason is if OS is case-insensitive it assumes that folder already exist but java compiler not.
Other solution (except leaving app package as it is) is to :
rename all packages in app to other that differ to app package or to
use OS that is case-sensitive (macOS could be formatter this way or
linux)
I had the same issue, After spending several hours had to change the name of the layout to make it work.
Steps I followed to make it work.
Tried clean build, invalidate cache, enable/disable binding. ( didn't work)
Got a suggestion from one of my fellow developer to recreate and rename the XML file. (It worked) !!
I`ve encountered this one also. If ever Basti Vagabond Instruction did not work try to search the entire files.
Just Follow this instruction below:
Edit->Find->Replace in Files (then search the old package name and replace it with your new package name).

Rename classes in gradle

I am preparing a Gradle build script for my Android application. Before build task starts I've to change main class name and thus change imports in each *.java file.
For example, if now my main class is com.company.myApp, so the packages in each java file are imported in following way: import com.company.myApp.pacakge.* and when I rename main class to com.company.newName I've also to change imports to: import com.comapny.newName.package.*.
I am beginner with Gradle but I was trying to find information about equivalent of replace() function and I found shadow plugin but it works on JAR files. There is one more soultion which is using ReplaceTokens but it works with tokens and class name is not a token like.
Is there any way to do it with Gradle?
For others with similar issue, changing any string to other using Gradle is quite easy. I've resolved my problemu using:
copy {
from "src_tmp"
into "src"
filter {
String line -> line.replaceAll("com.company.app", "com.new.string")
}
}

Package Rename Issue FBReader

While renaming the package in android eclipse, I am getting an error W/System.err(10980): java.lang.NoClassDefFoundError: org/geometerplus/fbreader/formats/PluginCollection and such errors, I renamed the package in manifest.xml by using refactor->rename. Can anybody tell me what is the issue.
Please mention how you did that.BTW here is rough idea: right click on project select android tools and from there select rename package options.
There are few reasons why this may occur. Class files are bytecode that Java interprets to execute your program. The following must be checked to ensure proper functioning of the application.
Class file located, Exception raised while initializing static blocks.
ClassNotFoundException -- .class not found for that referenced class irrespective of whether it is available at compile time or not(i.e base/child class).
Class file located, but Exception raised while initializing static variables
The error indicates, that something was found at compiletime but not at runtime, maybe you just have to add it to the classpath.
Right click on your project and select -> Compile Module, and then re-start the project and it should work again.
In eclipse make sure you have the shapes, linepoints and the spaceobjects as entries in the .classpath file.

how can I add the aidl file to Android studio (from the in-app billing example)

I am currently migrating an Eclipse app to Android Studio.
This app was using the in app billing.
My main problem is to compile the project and the aidl file (I guess you all use this file)
I get this error message:
Gradle: error: cannot find symbol class IInAppBillingService
Gradle: error: package IInAppBillingService does not exist
So, following some tutorials, I move this file from com.mypackage.billing to src/main/aidl
(see this reference)
But as soon, as I do that, I get this message:
Gradle: Execution failed for task ':xxxxxxxxxxx:compileDebugAidl'.
Failed to run command:
(...) C:\Users\xxxx\AndroidStudioProjects\xxxxxxProject\xxxxxxx\src\main\aidl\IInAppBillingService.aidl:45
interface IInAppBillingService should be declared in a file called
com\xxxxxxxx\billing\IInAppBillingService.aidl.
The message is clearly a contradiction with the post from the Google bug page I linked above.
Anyone suceeded to make this aidl file to work and can help me?
Just to inform, some links I followed:
http://tools.android.com/tech-docs/new-build-system/user-guide
http://developer.android.com/guide/components/aidl.html
Adding this as an answer since it seemed to help quite a few people.
Create a new directory named 'aidl' under 'src/main/'. It should look like 'src/main/aidl'.
Add a new package name 'com.android.vending.billing' to the directory 'src/main/aidl'
Locate your sdk location and go to "sdk\extras\google\play_billing". Default location for the sdk is "C:\Program Files (x86)\Android\android-sdk". If you custom changed it, then you will have to figure out the location through the sdk manager.
Copy 'IInAppBillingService.aidl' into the package created above. In the end, it should look similar to the image below.
Rebuild project and it should be good to go.
Note: Make sure you include the necessary import if your reference isn't working
import com.android.vending.billing.IInAppBillingService;
https://issuetracker.google.com/issues/36973270
Edit From Comment
After I did this, the references to IInAppBillingService in my code were still highlighted as errors, but after rebuilding the app, the class was recognized
Just as the error message says, you need to put IInAppBillingService.aidl in the correct directory dictated by it's package (com.android.vending.billing).
Within the src/main/aidl/ folder you already have, put the .aidl file in com/android/vending/billing/.
Create new directory under src/main called aidl
Right click on directory aidl, select new->add package
Enter Name of the package com.android.vending.billing
Copy IInAppBillingService.aidl from the directory Android/Sdk/extras/google/play_billing to the directory App_name/app/src/main/aidl/com/android/vending/billing
Now go ahead with InApp billing coding and while defining InApp related services you will get an error can not resolve symbol IInAppBillingXXXXXX
Now goto to Build from android studio menu , click on Rebuild Project. This will generate IInAppBillingService.java file inside App_Name/app/build/generated/source/aidl/debug/com/android/vending/billing. This will solve the issue.
The rest of posts here didn't work for me till I created a new folder like shown here.
Add this code in build.gradle
android {
sourceSets {
main {
aidl.srcDirs = ['src']
}
}
}
Rebuild and import aidl class
The above answers concentrate on file location, but it appears you already had that set correctly. I experienced this same issue in Android Studio, but none of the listed answers resolved it, and I banged my head against it for an hour. Eventually, I realized that I was missing an obvious import:
import com.android.vending.billing.IInAppBillingService;
Once I added that it resolved this error message.
This import isn't mentioned in any of the Google Billing docs or included in any of the code examples that I found. While it may be obvious to experienced Java developers, beginners just trying to learn their first project may need it explicitly pointed out.
We need to add
create folder - src/main/aidl/packagename and place aidl file under this.
In the aidl file - mention the package name.
package packagename
Now clean the project, rebuild the project - We can the corresponding java file for the aidl generated in app\build\generated\source\aidl\debug\packagename\youraidl.java
I know it sounds so easy, but I copy paste from google sample all folder
https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive/app/src/main
aidl/com/android/vending/billing
copied into project aidl ( I had set project view in Android Studio)
and next I clean and rebuild project and it found a reference.
I've tried every solutions, but the problem was that Android Studio had compiled, with any apparent reason, in a different build type of the module that contains the AIDL packages than it was specified by the settings.
From debug to release, so the other modules couldn't see the AIDL pkg.
Switching from debug to release and turns back, solved my problem.
restarting Android Studio worked for me
a second silly thing that took me a while. I dropped the code on Android Studio to allow him create the file, but he created a .java (as expected) instead a .aidl Jiji, stupid of me
if you do all the names correct go to Build>rebuild project
it worked for me
I use Android Studio 4.1, just right click mouse -> New -> AIDL -> AIDL File.
A file will be created and placed in the [src/main/aidl] folder automatically. The aidl folder will also be created if it does not exist.
This function only supports min sdk 16+. My old project still can be supported, you can temporarily modify the min sdk to 16, create aidl and build project. After the relative interface and class be generated, recover the min sdk settings, it also works and builds project well then.

Categories

Resources