When I configured my apklib I included:
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.0_r3</version>
<scope>provided</scope>
</dependency>
in the dependencies list. If I don't do that it won't recognize the source code in the editor
and won't compile. However, my question is, does the Android SDK then get included into the
project that uses the apklib? It seems so. However, why would it be so? I thought which SDK to use should be only decided by the project that uses the apklib rather then the apklib itself(?). I don't want to use an apklib that for example use api-level 19 when I use api-level 14 in my main project.
In short: Does an SDK dependency in the apklib pom get included into the main project (using Maven)?
I got it.
One should use scope=provided for the dependency.
Then, Maven assumes that the container project supplies the classes, and so the SDK classes don't get imported together with the apklib.
Related
I need to include appcompat-v7 in a maven build. Please note this is a question about a library with resources and not a jar. It's currently an aar artifact. The documentations on the SDK Deployer does not cover version 23.1.0 or version 23.0.1. I need to know what dependency needs to be in pom to include the compatibility library. Its either aar or apklib, and or also the include of a jar file as well. If anyone has got this working I would appreciate it if you would share the correct pom dependency. This problem appears to have been solved here:
How can I add an apklib dependency to your android maven project?
but this solution expressed in latest Android would be:
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v7-appcompat</artifactId>
<version>23.1.0</version>
<type>apklib</type>
</dependency>
This does not work now because apklib is not what is there. It is aar and changing type to aar does not seem to work either. Resulting in lots of conflicts or missing classes or class conflicts. I can think of no more commonly needed library from SDK Deployer than this. So could someone please answer the quesiton. In addition, I think the documentation of the deployer should reflect current versions, not just versions that are years old. Thanks.
The documentation of the SDK deployer references all dependencies that are custom created in addition to the ones from the repositories of the SDK itself. You can run the deployer and deploy all the components into a repository manager like Nexus and then search there or you can browse the local file system repository in ~/.m2/repository. For example look in the directory ~/.m2/repository/com/android/support/appcompat-v7/
In your case you probably want to use something like
<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<version>23.1.1</version>
<type>aar</type>
</dependency>
This is all mentioned in the docs. And the deployer is open source and I do accept pull requests ;-)
I want to use android.support.v7.widget.SwitchCompat
This is more of a problem than I ever imagined. I need to know the exact steps to include v7 compatibility library in maven build.
So far I either run into class not found error on android.support.v7.widget.SwitchCompat or when I include that jar,or I get exception related to not finding R.attr at runtime when it compiles ok.
So I need to know exactly what needs to be done to compile v7 so that everything I need is in the APK.
I don't see that classes.jar inside apklib even has the R.attr etc.
Could someone just tell me exactly what I need to do include v7 compatibility in my maven build.
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v7</artifactId>
<version>23.0.1</version>
<type>apklib</type>
<scope>system</scope>
<systemPath>${basedir}/libs/appcompat-v7-23.0.1.jar</systemPath>
</dependency>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<version>23.0.1</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${basedir}/libs/android-support-v7-appcompat.jar</systemPath>
</dependency>
I have seen it said before to use compile scope, but this is not available if the libs are on system. It must use system scope.
Now in the past I always use eclipse, and when something was missing at runtime it was always just a matter of 'exporting' certain jars in ide, so now with pure maven pom build, I don't know what to do. It needs to be built on server where eclipse is not part of the build process. What I am not getting is what is telling the build to include the classes like R.attr at runtime related to this UI library? I need to resources at runtime. In the past, I always just depended on eclipse exporting of jars for this and link to the library. Now it is not so clear ...
Can someone tell me how to tell maven to check my local repo for items? Right now if it does not find an item on server it ends in error even if I installed items locally in on files system \username.m2
Here is error:
java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$attr
What is the correct procedure to include a library with resources like this?
I'm trying to include android compatibility v7 library in apk. it compiles but cannot find resources at runtime. I uploaded the compatibility library to my local repo (jar file only), and included it as a maven dependency as follows:
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v13</artifactId>
<version>23.1.0</version>
</dependency>
Is this enough to get the resources included too? It just downloads a jar which is all I uploaded to my local repo. How do I include the resources as well in the maven build? If we used the maven sdk deployer instead would including the maven dependency alone be enough? or do I need to create whole project and somehow link to library? This is being built on server so I need pom to pull everything needed. How do I get it included as library not just jar?
I think you have remaining below maven tag in dependency.
please add this:
<type>jar</type>
Check this link for more.
I'm converting an android application to be maven-based
what I've done is:
Insert pom.xml
List item
copy java classes into main/java directory and make this directory
the source path
insert the maven nature into .project file
I add the google android library dependency into pom.xml:
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.1.2</version>
<scope>provided</scope>
</dependency>
I then realised that I don't need the android library to be included in the class path as I'm actually refering it from the pom.xml
So I removed the library, and what happend is the the project has compilation errors, though It exports the apk successfully when I right click > Run As> Maven Install, and this means that this project is a correct project from a maven perspective, so what's wrong with eclipse ??
What I found is that the Maven Dependency Library is abscent when I set the library scope as provided,
<scope>provided</scope>
but is back when I set the dependency to it's default(Compile),
<scope>compile</scope>
Though this scope makes maven fail to package as this library is a core library that must not be included, and anyway I find it a terrible solution even if it's packaging well
What am I missing here ??
NB: I'm using MotoDev IDE
It turned out that there is an issue with the android-maven-plugin with apk packaging ... will post the solution when solved
This must be a very stupid newbie question, but I have spent my whole day trying to figure out what is wrong with this thing.
I was about to include a dependency on Sherlock Action bar into my Android-Maven project. The site made a repo to support maven-android setup. I know that I was supposed to just include the dependency, then specify the repo inside the pom, that I have managed to do, but to no luck did this just not work for me.
these are the dependency and repository tags I used
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId>
<version>3.5.1</version>
<type>apklib</type>
</dependency>
and this
<repository>
<id>jakewharton</id>
<url>http://r.jakewharton.com/maven/release/</url>
</repository>
i don't have any errors at all. It's just that I can't see the APKLIB under the maven dependencies directory on my package explorer at eclipse. But most importantly, I can't use the packages/classes under the apklib.
Am I missing anything?
This special type of apklib dependency only works in android-maven-plugin from command line console. adding it as a dependency in your main project's POM does not automatically import the library project into your Eclipse, so no library project shown in Package Explorer.
Simply adding the apklib as a dependency in pom doesn't help much for project development. as packages/classes under the apklib is not referenced/linked to your main project. it is different from the regular jar dependency, where you simply add jar dependency into your project and start import/use packages/classes in your main project.
Your need import the library project into your Eclipse workspace, and link it with your main project. As you already use android-maven-plugin, the most straight forward way to do this is change your maven project into multi-module project and add the library project as a sub-module
check out the LibraryProjects from android-maven-plugin sample here
Hope this help.