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
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 ;-)
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.
My development environment:
adt:22.3.0
android-maven-plugin:3.8.2
maven:3.1.1
I am developing a google map Android app with maven structure and dependencies as below:
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>13.0.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>13.0.0</version>
</dependency>
or
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>play-services</artifactId>
<version>4.0.30</version>
<type>aar</type>
</dependency>
I tried apk and aar type but I still can't use resource drawable, string etc (R.drawable.poi, R.style.button_style1..) in android lib dependency. How can I handle this?
To use the resource drawables of Library, you also have to import the project into eclipse workspace and reference it from your mavenized project.
I faced this problem, solved it by importing Google-play-services project to workspace and referencing it from my maven project.
For referencing. right click on your project->Properties->Android->(libraryProjects->Add->[browse google-play-library project]), click on apply and save it.
you can find google-play-library project in sdk/extras/google/
A similar problem appeared in our project after updating android-maven-plugin from version 3.8.0 to 3.8.2, android-maven-plugin looks bugy.
We had to fallback to version 3.8.0. I recommend you to do the same using apklib as aar is only available since version 3.8.2 and in case you want to use aarto wait for later version of android-maven-plugin.
In details, the problem was in the linking of the apklib, all ressources (layouts, drawables...) referenced seemed to be disaligned. For example a layout or a drawable was displayed instead of another. Application was crashing when accessing to a missing reference/id in a layout (the reference was not present because the wrong layout was loaded).
See issue http://code.google.com/p/maven-android-plugin/issues/detail?id=441
I have an android project which I am developing on eclipse and building with maven. I wanted to include a lib (apklib) in it, and similarly to other includes, I have tried appending the dependency to my pom in the following way:
<dependency>
<groupId>groupID.name</groupId>
<artifactId>artifact.name</artifactId>
<version>version</version>
</dependency>
However, when trying to build it either from m2eclipse or from maven on the console, I would get an error
(Failed to execute goal on project projectName: Could not resolve
dependencies for project project Failure to find apklib in
repo was cached in the local repository, resolution will not be reattempted until the update interval of repo has elapsed or
updates are forced)
saying that this dependency could not be found even if I can see the dependency in my .m2 directory
The solution was quite simple, but since I found it through an example trying to demonstrate something else, rather than a Q&A (and I did not find it easily in the maven-android-plugin project,) I decided to share it here with the hope it can help someone.
The solution was just to set my dependency type to apklib in this way:
<dependency>
<groupId>groupID.name</groupId>
<artifactId>artifact.name</artifactId>
<version>version</version>
<type>apklib</type>
</dependency>
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