Unable to resolve twilio dependancy issue in aem | Community
Skip to main content
Adobe Employee
May 3, 2024
Solved

Unable to resolve twilio dependancy issue in aem

  • May 3, 2024
  • 3 replies
  • 2368 views

Hi Everyone,

      I have to use twilio message api [https://www.twilio.com/en-us], For that I have added dependancy in core pom file like below to use their apis.

 

core pom.xml:

<!-- communication web API https://mvnrepository.com/artifact/com.twilio.sdk/twilio -->
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<version>10.1.5</version>
</dependency>

 

Post this, I got below build error:

if I build core module- build is success but getting cannot be resolved issue.

 

if I build whole project I got below build error:

[ERROR] The analyser found the following errors for author and publish :
[ERROR] [api-regions-exportsimports] com.sampleproject:sampleProject.core:1.0.0-SNAPSHOT: Bundle sampleProject.core:1.0.0-SNAPSHOT is importing pack
age(s) [com.twilio.type, com.twilio, com.twilio.rest.api.v2010.account, com.twilio.base] in start level 20 but no bundle is exporting these for that start level. (com.sampleproject:sampleProject.all:1.0.0-SNAPSHOT)

 

Due to above error I have embeded this in all pom.xml and I got another build error like below:

all pom.xml

<embedded>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<type>jar</type>
<target>/apps/sampleProject-packages/application/install</target>
</embedded>

Post this, I got below build error:

[ERROR] Failed to execute goal com.adobe.aem:aemanalyser-maven-plugin:1.4.10:project-analyse (aem-analyser) on project sampleProject.all: A fatal er
ror occurred while analysing the features, see error cause:: Unable to get bundle symbolic name from artifact com.twilio.sdk:twilio:10.1.5 -> [Help 1]

 

FYI - It looke like not a bundle, it's jar file. So I need your help to solve this dependancy issue, Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jagadeesh_Prakash

@jagadeesh_prakash , I have added whatever you have mentioned in previous chat. Still I'm getting below error, can you try with below servlet?
ERROR:
[ERROR] The analyser found the following errors for author and publish :
[ERROR] [api-regions-exportsimports] com.sampleproject:sampleProject.core:1.0.0-SNAPSHOT: Bundle sampleProject.core:1.0.0-SNAPSHOT is importing pack
age(s) [com.twilio.type, com.twilio, com.twilio.rest.api.v2010.account, com.twilio.base] in start level 20 but no bundle is exporting these for that start level. (com.sampleproject:sampleProject.all:1.0.0-SNAPSHOT)

Servlet:
servlet call won't work in your post call but maven build should be success

package com.sampleproject.core.servlets;

import lombok.extern.slf4j.Slf4j;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import java.io.IOException;

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS;

@Component(service = { Servlet.class },
property = {
SLING_SERVLET_PATHS + "=/bin/sendmessage"
})
@Slf4j
public class MessageServlet extends SlingAllMethodsServlet {
public static final String ACCOUNT_SID = "abcd";
public static final String AUTH_TOKEN = "efgh";

@Override
protected void doPost( SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
Twilio.init("abcd", "efgh");
Message message = Message.creator(
new com.twilio.type.PhoneNumber("+919700606004"), //To number
new com.twilio.type.PhoneNumber("+13347006328"), //from number
"Hi, Admin sending a test message?")
.create();
log.debug(message.getSid());
response.getWriter().write("responsemessage:" +message.getSid());
}
}





@jeromeleslyv 

I was just checking the build success message and confirmed that it's working. 

I work on your example and faced the same issue. Below is the recommendation 

 

Step 1: convert the Jar to OSGi bundle refer to below link

https://experienceleague.adobe.com/en/docs/experience-cloud-kcs/kbarticles/ka-17475

 

Step 2: load the bundle from your project location or from your separate artifact repo

 

Step 3: 

embed the package as shown in below plugin example

 

<embedded>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<type>jar</type>
<target>/apps/<your-project>/application/install</target>
</embedded>

 

<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../<your-project>.ui.apps/src/main/resources/twilio-10.1.5.jar</systemPath>
</dependency>

3 replies

Jagadeesh_Prakash
Community Advisor
Community Advisor
May 3, 2024

@jeromeleslyv 

The Twilio SDK is not an OSGi bundle out of the box, so you cannot directly include it as a dependency in your AEM project.

  1. Embed the Non-OSGi Dependencies: You can embed the Twilio SDK in your project's bundle. This will include the Twilio SDK classes directly in your bundle, allowing you to use them even though they're not OSGi bundles. You can do this by adding the <Embed-Dependency> instruction in your maven-bundle-plugin configuration in your pom.xml:<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
    <instructions>
    <Embed-Dependency>twilio;scope=compile|runtime;inline=true</Embed-Dependency>
    <!-- other instructions -->
    </instructions>
    </configuration>
    </plugin>
  2. Convert the Dependencies to OSGi Bundles: You can use the Apache Felix Maven Bundle Plugin to convert the Twilio SDK into an OSGi bundle. This involves creating a separate project that wraps the Twilio SDK and adds the necessary OSGi metadata. This is a more complex solution, but it allows you to manage the Twilio SDK as a separate bundle in your AEM instance.
Adobe Employee
May 3, 2024

I have added like this in core pom.xml is this correct?

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>twilio;scope=compile|runtime;inline=true</Embed-Dependency>
<Bundle-SymbolicName>com.twilio.sdk.twilio</Bundle-SymbolicName>
<Bundle-Name>twilio</Bundle-Name>
<Bundle-Version>10.1.5</Bundle-Version>
<Private-Package>com.twilio.*</Private-Package>
</instructions>
</configuration>
</plugin>
Jagadeesh_Prakash
Community Advisor
Jagadeesh_PrakashCommunity AdvisorAccepted solution
Community Advisor
May 8, 2024

@jagadeesh_prakash , I have added whatever you have mentioned in previous chat. Still I'm getting below error, can you try with below servlet?
ERROR:
[ERROR] The analyser found the following errors for author and publish :
[ERROR] [api-regions-exportsimports] com.sampleproject:sampleProject.core:1.0.0-SNAPSHOT: Bundle sampleProject.core:1.0.0-SNAPSHOT is importing pack
age(s) [com.twilio.type, com.twilio, com.twilio.rest.api.v2010.account, com.twilio.base] in start level 20 but no bundle is exporting these for that start level. (com.sampleproject:sampleProject.all:1.0.0-SNAPSHOT)

Servlet:
servlet call won't work in your post call but maven build should be success

package com.sampleproject.core.servlets;

import lombok.extern.slf4j.Slf4j;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import java.io.IOException;

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS;

@Component(service = { Servlet.class },
property = {
SLING_SERVLET_PATHS + "=/bin/sendmessage"
})
@Slf4j
public class MessageServlet extends SlingAllMethodsServlet {
public static final String ACCOUNT_SID = "abcd";
public static final String AUTH_TOKEN = "efgh";

@Override
protected void doPost( SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
Twilio.init("abcd", "efgh");
Message message = Message.creator(
new com.twilio.type.PhoneNumber("+919700606004"), //To number
new com.twilio.type.PhoneNumber("+13347006328"), //from number
"Hi, Admin sending a test message?")
.create();
log.debug(message.getSid());
response.getWriter().write("responsemessage:" +message.getSid());
}
}





@jeromeleslyv 

I was just checking the build success message and confirmed that it's working. 

I work on your example and faced the same issue. Below is the recommendation 

 

Step 1: convert the Jar to OSGi bundle refer to below link

https://experienceleague.adobe.com/en/docs/experience-cloud-kcs/kbarticles/ka-17475

 

Step 2: load the bundle from your project location or from your separate artifact repo

 

Step 3: 

embed the package as shown in below plugin example

 

<embedded>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<type>jar</type>
<target>/apps/<your-project>/application/install</target>
</embedded>

 

<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../<your-project>.ui.apps/src/main/resources/twilio-10.1.5.jar</systemPath>
</dependency>
EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 3, 2024
kautuk_sahni
Community Manager
Community Manager
May 16, 2024

@jeromeleslyv Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni