Android custom class dependency for aidl - java

So I have the following project structure:
.
├── Central
│ ├── app
│ │ ├── build.gradle
│ │ └── src
│ ├── build.gradle
│ ├── gradle.properties
│ └── settings.gradle
└── Client
├── app
│ ├── build.gradle
│ └── src
├── build.gradle
├── gradle.properties
└── settings.gradle
In the Central app, I define a service and along with it an AIDL interface. In the AIDL, one of the functions returns a custom object (which extends Parcelable). In the Client app, I put the exact same AIDL file (under the same package in the src/aidl directory). I try to import the custom class by declaring a gradle dependency to the Central app.
Here is the Client's settings.gralde
rootProject.name='Client'
include ':app'
include ":Central"
project(":Central").projectDir = file('../Central/app')
The Client's app/build.gralde:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.Patel.Cli3n5"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(path: ':Central', configuration: 'default')
}
And the aidl file (present in both apps):
package com.Patel.Central;
import android.graphics.Bitmap;
parcelable Info;
interface MusicCentral {
List<Info> getAllSongsInfo();
Bitmap getSongImage(int songNum);
}
And note that the Info class is defined in the package com.Patel.Central.
When I try to build the Client app, I get the following error:
error: cannot find symbol
#Override public java.util.List<com.Patel.Central.Info> getAllSongsInfo() throws android.os.RemoteException
In summary, the problem is that there is a custom class and I need to import from an app that is in another directory.

You need to define both files
Info.java
and
Info.aidl seprate aidl file for Info.java
with same package name at both client and remote application.
means package should have
MusicCentral.aidl
Info.java
Info.aidl
in com.Patel.Central package.

Related

Multiple gradle versions

I have a java project in Visual Studio Code with some subprojects:
javaProject
├── README.md
├── build.gradle
├── chronos
│ ├── build.gradle
│ ├── settings.gradle
│ ├── src
├── crate-generator-strategy
│ ├── build.gradle
│ └── src
├── dafne
│ ├── build.gradle
│ ├── settings.gradle
│ └── src
├── gradle.properties
├── hermes
│ ├── build.gradle
│ ├── settings.gradle
│ ├── src
├── meti
│ ├── build.gradle
│ ├── settings.gradle
│ └── src
└── settings.gradle
Under the main dir javaProject there's a dir called .gradle and in that I have different versions of gradle (i.e. 6.4, 7.1.1, 7.4.1)
In my system I have only the 7.4.1 version installed.
------------------------------------------------------------
Gradle 7.4.1
------------------------------------------------------------
Build time: 2022-03-09 15:04:47 UTC
Revision: 36dc52588e09b4b72f2010bc07599e0ee0434e2e
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 17.0.2 (Homebrew 17.0.2+0)
OS: Mac OS X 12.1 x86_64
If I delete the dir, it suddenly reappear with all the versions.
Why there are many versions and not the installed one?
How could I get rid of the old ones?
Thanks,
S.

Cannot resolve symbol 'EnableJpaRespositories' even though specified in build.gradle

For some reason, I'm unable to get a module within my project to detect that it has the dependencies in place to pick up #EnableJpaRepositories. Despite having implementation 'org.springframework.boot:spring-boot-starter-data-jpa' specified in my build.gradle file, when I run gradle to try and compile, I get the following error:
./gradlew clean build
> Task :rest:compileJava FAILED
/Users/pasdeignan/git/pasciifinance/rest/src/main/java/com/pasciitools/pasciifinance/rest/PasciifinanceApplication.java:22: error: cannot find symbol
#EnableJpaRespositories(basePackages="com.pasciitools.pasciifinance")
^
symbol: class EnableJpaRespositories
1 error
FAILURE: Build failed with an exception.
Background
I have a multi-module Spring project that I'm building where I'm trying to store the JPA pieces in a common module and the REST services in a rest module. The rest module is also where my SpringBootApplication lives. When I start up the application, I get the following error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field accountRepo in com.pasciitools.pasciifinance.rest.PasciifinanceApplication required a bean of type 'com.pasciitools.pasciifinance.common.repositories.AccountRepository' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.pasciitools.pasciifinance.common.repositories.AccountRepository' in your configuration.
Project Structure
pasciifinance
└── build.gradle (empty)
└── settings.gradle
└── common
└── build.gradle
└── src
└── main/java/com/pasciitools/pasciifinance/common
└── entity
└── repository
└── AccountRepository.java
└── rest
└── build.gradle
└── src
└── main/java/com/pasciitools/pasciifinance/rest
└── PasciiFinanceApplication.java
└── restservice
└── RestService.java
PasciiFinanceApplication.java
package com.pasciitools.pasciifinance.rest;
import com.pasciitools.pasciifinance.common.entity.Account;
import com.pasciitools.pasciifinance.common.entity.AccountEntry;
import com.pasciitools.pasciifinance.common.repository.AccountEntryRepository;
import com.pasciitools.pasciifinance.common.repository.AccountRepository;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.util.List;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
#EnableEncryptableProperties
#EnableJpaRespositories(basePackages="com.pasciitools.pasciifinance")
#SpringBootApplication(scanBasePackages = "com.pasciitools.pasciifinance")
public class PasciifinanceApplication {
#Autowired
private AccountRepository accountRepo;
#Autowired
private AccountEntryRepository entryRepo;
private static final Logger log = LoggerFactory.getLogger(PasciifinanceApplication.class);
public static void main(String[] args) {
SpringApplication.run(PasciifinanceApplication.class, args);
}
}
build.gradle (rest module)
plugins {
id 'org.springframework.boot' version '2.4.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.pascii-tools'
version = '0.0.1-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation project(':common')
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.apache.poi:poi:5.0.0'
implementation 'org.apache.poi:poi-ooxml:5.0.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
implementation 'com.github.ulisesbocchio:jasypt-spring-boot:3.0.3'
implementation 'org.springframework.boot:spring-boot-starter-batch'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
runtimeOnly 'com.h2database:h2'
}
test {
useJUnitPlatform()
}
build.gradle (common)
plugins {
id 'org.springframework.boot' version '2.4.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.pascii-tools'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 11
repositories {
mavenCentral()
}
bootJar {
enabled = false
}
jar {
enabled = true
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
You have a typo in #EnableJpaRespositories.
You'll need to rename it to #EnableJpaRepositories, as you've asked in your question.

Gradle integration test produces java.lang.NoClassDefFoundError

I am migrating multi-module Gradle Java project from Gradle 4.10 to Gradle 6.3.
Project structure looks like the following:
├── build.gradle
├── our-webapp
│   ├── build.gradle
│ └── src
│ ├── main
│ ├── integrationTest
│ └── test
└── cli-util
├── build.gradle
└── src
├── main
├── integrationTest
└── test
cli-util has a dependency on webapp to use it's classes.
build.gradle looks like:
plugins {
id 'java'
}
sourceSets {
integrationTest {
compileClasspath += sourceSets.main.output + sourceSets.test.output
runtimeClasspath += sourceSets.main.output + sourceSets.test.output
java.srcDir 'src/integrationTest/java'
resources.srcDir 'src/integrationTest/resources'
}
}
configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntime.extendsFrom testRuntime
}
dependencies {
implementation project(':our-webapp')
}
task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
And now what is interesting is that tests under cli-util/src/intergrationTest are working fine in Intellij IDEA but they are failing from terminal whenever there is an import of a class defined in webapp project. The error is java.lang.NoClassDefFoundError: com/example/web/SomeClass.
I tried different approaches already, including the use of java-library plugin in cli-util project and importing webapp project like api project(':our-webapp') but it still fails.
Same issue in Gradle 5.6.x.
Is there some special change I have take into account to make it work?

Run java application on Tomcat with Gradle

I have a project structure as follows:
└── src
├── main
│   ├── java
│   │   ├── MessageServlet.java
│   └── webapp
│       ├── META-INF
│       │   └── context.xml
│       ├── WEB-INF
│       │   └── web.xml
│       ├── index.html
│       └── style.css
└── test
└── java
I also have a tomcat server which I run using the gradle below. The tomcat server starts and displays the index.html page. But, when I try to run the servlet i get following error message:
HTTP Status 500 - Error instantiating servlet class MessageServlet
build.gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.4'
}
}
apply plugin: 'com.bmuschko.tomcat'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'org.mongodb:mongo-java-driver:3.3.0'
compile 'com.google.code.gson:gson:2.2.4'
def tomcatVersion = '8.0.42'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"
}
QUESTION
I want to run the project on my tomcat server via this gradle. How do I make the gradle execute MessageServlet.java together with tomcat?

Gradle - dont create parent build in multi module project [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have project with structure like this:
┌project
│
├── build.gradle
├── module 1
│ │
│ ├── build.gradle
│ ├── module 1.1
│ └── module 1.2
│
└── module 2
│
├── build.gradle
├── module 2.1
└── module 2.2
My problem is that I have builds created for project, module 1 and module 2. But I do not need them, I only need builds from module 1.1, 1.2, 2.1 and 2.2.
In submodules build.gradle:
project(":modules 1") {
ext.buildables = [
project(':modules-1:modules.1.1'),
project(':modules-1:modules.1.2')]
}
project(":modules-1:modules.1.1") {
dependencies {
...
}
}
In root build.gradle:
subprojects {
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
Any thoughts on this?
Edit:
After running gradle build, there is follwoing directory structure:
┌project
│
├── build.gradle
├── build (not wanted)
├── module 1
│ │
│ ├── build (not wanted)
│ ├── build.gradle
│ ├── module 1.1
| | |
│ | └── build
│ └── module 1.2
| |
│ └── build
│
└── module 2
│
├── build (not wanted)
├── build.gradle
├── module 2.1
| |
| └── build
└── module 2.2
|
└── build
How to get rid of these not wanted folders, they all have jars with size of 1kb inside.
Thanks to #Opal for providing link to this discussion.
Added following to allprojects, which skips empty jars.
jar {
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
}

Categories