Error with Maven Dependencies when building HoloEverywhere - android

I'm trying to use HoloEverywhere in an Android application but I cannot get it to work properly. Whenever I try to import the library I get some errors. After Googling I've been able to remove error up to this one:
The container 'Maven Dependencies' references non existing library
'C:\Users\myself\.m2\repository\com\google\android\support-v4\r12\support-v4-r12.jar'
I have this library in the folder "HoloEverywhere-master\support-library" because it is included with HoloEverywhere. I am not at all familiar with Maven so I'm not too sure what exactly it is trying to do. Any ideas?

check this dependency in pom.xml , you can link it as dependency with system scope :
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r12</version>
<scope>system</scope>
<systemPath>${project.basedir}/external/something.jar</systemPath>
</dependency>
then just correct system path. This is just quick fix. A bit better solution is to install that jar library into your local repository with this command :
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
OR
look for maven repository which contains given library e.g. :
http://mvnrepository.com/artifact/com.google.android/support-v4/r6 (be carefull this is r6 version and you propably need r12)
<repositories>
<repository>
<id>my-alternate-repository</id>
<url>http://myrepo.net/repo</url>
</repository>

Is this really a Maven problem?
Have you tried Right-clicking on your project.
Selecting Android Tools > Add Support Libraries...

Related

Android Maven SDK Deployer

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 ;-)

How do I add a library (android-support-v7-appcompat) in IntelliJ IDEA

I created a project, copied the resource files in the project, library, added it to the project structure, prescribed style Theme.AppCompat.
Compiled without errors, but when you start the relegation Exception:
08-03 00:50:00.406: ERROR/AndroidRuntime(4055): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:98)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at com.example.SampleMetrRost.CentralActivity.onCreate(CentralActivity.java:12)
at android.app.Activity.performCreate(Activity.java:4636)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1924)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:583)
at dalvik.system.NativeStart.main(Native Method)
Help me, please. Spent all day today.
Using Gradle
If you are using Gradle, you can add it as a compile dependency.
Instructions
Make sure you have the Android Support Repository SDK package installed. Android Studio automatically recognizes this repository during the build process (not sure about plain IntelliJ).
Add the dependency to {project}/build.gradle
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
Click the Sync Project with Gradle Files button.
EDIT: Looks like these same instructions are on the documentation under Adding libraries with resources -> Using Android Studio.
Without Gradle (Click here for the Gradle solution)
Create a support library project.
Import your library project to Intellij from Eclipse project (this step only applies if you created your library in Eclipse).
Right click on module and choose Open Module Settings.
Setup libraries of v7 jar file
Setup library module of v7
Setup app module dependency of v7 library module
Using Maven
First of all you should install android libraries to your local maven repository using Maven Android SDK Deployer
Then you can add dependency to your pom like this:
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v7-appcompat</artifactId>
<version>${compatibility.version}</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v7-appcompat</artifactId>
<version>${compatibility.version}</version>
<type>jar</type>
</dependency>
This is my solution:
Copy&paste $ANDROID_SDK/extras/android/support/v7/appcompat to your project ROOT
Open "Project Structure" on Intellij, click "Modules" on "Project Settings", then click "appcompat"->"android', make sure "Library Module" checkbox is checked.
click "YOUR-PROJECT_NAME" under "appcompat", remove "android-support-v4" and "android-support-v7-compat"; ensure the checkbox before "appcompat" is checked. And, click "ok" to close "Project Structure" dialogue.
back to the mainwindow, click "appcompat"->"libs" on the top-left project area. Right-click on "android-support-v4", select menuitem "Add as library", change "Add to Module" to "Your-project". Same with "android-support-v7-compat".
After doing above, intellij should be able to correctly find the android-support-XXXX modules.
Good Luck!
Another yet simple solution is to paste these line into the build.gradle file
dependencies {
//import of gridlayout
compile 'com.android.support:gridlayout-v7:19.0.0'
compile 'com.android.support:appcompat-v7:+'
}
Another solution for maven (and a better solution, for me at least) is to use the maven repository included in the local android SDK. To do this, just add a new repository into your pom pointing at the local android SDK:
<repository>
<id>android-support</id>
<url>file://${env.ANDROID_HOME}/extras/android/m2repository</url>
</repository>
After adding this repository you can add the standard Google dependency like this:
<dependency>
<groupId>com.android.support</groupId>
<artifactId>support-v13</artifactId>
<version>${support-v13.version}</version>
</dependency>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<version>${appcompat-v7.version}</version>
<type>aar</type>
</dependency>
As a Library Project
You should add the resources in a library project as per http://developer.android.com/tools/support-library/setup.html
Section > Adding libraries with resources
You then add the android-support-v7-appcompat library in your workspace and then add it as a reference to your app project.
Defining all the resources in your app project will also work (but there are a lot of definitions to add and you have missed some of them), and it is not the recommended approach.
This is my solution, it is very similar to the previous one:
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v7</artifactId>
<scope>system</scope>
<systemPath>${android.home}/support/v7/appcompat/libs/android-support-v7-appcompat.jar</systemPath>
<version>19.0.1</version>
</dependency>
Where {android.home} is the root directory of the Android SDK and it uses systemPath instead of repository.
As an update to Austyn Mahoney's answer, configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see here.

How can I add an apklib dependency to your android maven project?

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>

Android Eclipse project compilation errors with maven provided 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

APKLIB does not get installed in Maven Repo

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.

Categories

Resources