IDEA+maven使用最新版本的support-v4-r19

maven使用support-v4最新版本是r7,没有r19 。比如

ActionBarSherlock do not have latest support library(https://github.com/JakeWharton/ActionBarSherlock/pull/853):


作者说:

We cannot update the support library since r7 is the latest in Maven central. If you need a newer version you should replace it in your local copy (or use Maven dependencies to trump it by deploying the newer jar). The library is also compiled with API 14 so the properties file is accurate.


解决方法有很多。下面给出一个比较简单的方法。


1.使用maven-android-sdk-deployer.


在本地maven 库中安装android sdk和support library.但是默认需要先使用android sdk manager下载所有sdk,这比较麻烦,但是可以

修改maven-android-sdk-deployer的extra/pom.xml文件,不安装某些模块。准备好maven和android sdk以及maven-android-sdk-deployer之后,在maven-android-sdk-deployer目录下执行mvn install即可。一个例子:


Remove module defs of admob and vcm for maven-android-sdk-deployer(https://github.com/ikuo/maven-android-sdk-deployer/commit/73f3e11c4b412791ea495cf82d0b32285aff8f29

)

(extra/pom.xml,注释不需要的即可) 

                 <module>compatibility-v13</module>

                 <!--<module>analytics-v1</module>-->

                 <module>analytics-v2</module>

-                <module>admob</module>

-                <module>gcm</module>

                 <module>google-play-services</module>

                 <module>google-play-services-for-froyo</module>

                 <module>play-licensing</module>


ls -alF /usr/local/android-studio/sdk/extras/google 


然后再pom.xml中修改为:


<dependency>

   <groupId>android.support</groupId>

  <artifactId>compatibility-v4</artifactId>

  <version>19.0.1</version>

</dependency>



或者

<dependency>

 <groupId>com.android.support</groupId> <artifactId>support-v4</artifactId> <version>19.0.1</version>


</dependency>



      <dependency>

          <groupId>com.actionbarsherlock</groupId>

          <artifactId>actionbarsherlock</artifactId>

          <version>4.4.0</version>

          <type>apklib</type>



          <!--actionbarsherlock use suppport library but the lastes version of suppport library in maven center is support-v4-r7.jar

          we can use local version support-v4-r19.jar-->

          <exclusions>

              <exclusion>

                  <groupId>com.google.android</groupId>

                  <artifactId>support-v4</artifactId>

              </exclusion>

          </exclusions>

      </dependency>








获取如果想用maven-android-sdk-deployer覆盖support包,那么执行



mvn install -Dextras.compatibility.v4.groupid=com.google.android \

            -Dextras.compatibility.v4.artifactid=support-v4 \

            -Dextras.compatibility.v4.version.prefix=r


mvn install -Dextras.compatibility.v13.groupid=com.google.android \

            -Dextras.compatibility.v13.artifactid=support-v13 \

            -Dextras.compatibility.v13.version.prefix=r


然后修改pom文件为



<!--<dependency>-->

          <!--<groupId>com.google.android</groupId>-->

          <!--<artifactId>support-v4</artifactId>-->

          <!--<version>r19.0.1</version>-->

      <!--</dependency>-->




<dependency>

          <groupId>android-support</groupId>

          <artifactId>support-library</artifactId>

          <version>r19</version>

          <scope>system</scope>

          <systemPath>${project.basedir}/libs/android-support-v4.jar</systemPath>

      </dependency>



以上都可以从maven的.m2目录下找到这些文件:


com.google.android

<?xml version="1.0" encoding="UTF-8"?>

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.google.android</groupId>

  <artifactId>support-v4</artifactId>

  <version>r19.0.1</version>

  <description>POM was created from install:install-file</description>

</project>


android.support

<?xml version="1.0" encoding="UTF-8"?>

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <modelVersion>4.0.0</modelVersion>

  <groupId>android.support</groupId>

  <artifactId>compatibility-v4</artifactId>

  <version>19.0.1</version>

  <description>POM was created from install:install-file</description>

</project>

com.android.support

<?xml version="1.0" encoding="UTF-8"?>

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.android.support</groupId>

  <artifactId>support-v4</artifactId>

  <version>19.0.1</version>

</project>


但是使用IDEA+maven,以上方法有个小小的问题(不影响结果):



http://youtrack.jetbrains.com/issue/IDEA-98114#comment=27-445745

http://youtrack.jetbrains.com/issue/IDEA-102349#



Ah, I understand. The problem is that our resolve strategy doesn't support such structure. Actually, it shouldn't affect compilation and just produces red code in the editor.



1. ABS code is compiled with the classpath containing "r7" (not "r12"), because ABS artifact depends on "r7", so it cannot use getChildFragmentManager() method, and it doesn't use it.

2. Your module (doesn't matter apk or apklib) is compiled with different classpath which contains "r12", but doesn't contain "r7", and it also contains ABS compiled classes (compiled with "r7")

3. Your fragment extends SherlockFragment which extends Fragment from the support library.



Because our resolving strategy is sequential, when you use getChildFragmentManager() in your fragment and we try to find this method in super classes, we first resolve the class you extends (it is SherlockFragment), it is located in the ABS module. Then we look for superclass of SherlockFragment and we come to Fragment from "r7", because ABS module depends on "r7" lib, and it doesn't contain getChildFragmentManager(). At the last step we don't take into account your module, only ABS module and its dependencies. So we're not able find getChildFragment() in this way.



Unfortunately, not yet. We're still working with the problem. It doesn't cause real issues when compiling, its just a bit annoying in the editor to show some errors.



I can't follow what you are trying to say Sven. getChildFragmentManager() was added in r11, which hasn't been added to ActionBarSherlock since it's not on Maven Central yet. The workaround is suppose to use Maven dependency management to get r11 Fragment into the SherlockFragments, I believed. And this is from the point of view of IDEA, as it should work if compiled. Nevertheless, It still doesn't allow me to use the method in SherlockFragments, even with the workaround in place.



What I was trying to say is that maybe ActionBarSherlock needs adjustments to be able to use the new features of support r11? But since SherlockFragment extends from android.support.v4.app.Fragment this should actually work. Maybe IDEA still takes the old support libary during compilation?



2.下面是一位老外的解决方法:

How to solve it:

This is problem if want to use support library imported  to the own repo by https://github.com/mosabua/maven-android-sdk-deployer

This conversation helped me to think and find the solution for my exact case. May be it would work for others of you. So the problem:

- ABS has old support library (r7) in its dependencies

- ABS has maven as primary build system

- My project requires lates support libraray because of PagerStrips for ViewPager

- My project has ant as build system and I am not going to change it by many reasons

- As some of you I also use IJIDEA for debuging


First I realised that ABS is an actual wrapper above support library. So I don't think it is a good idea to manage multiply versions of it. Let's keep only one version around and we won't have to be fighting with anything. 


What I've done:

- I forked ABS repo

- Put it as git submodule to my project

- Created VCS-based maven repository which is local to ABS project dir. I used approach from here http://blog.dub.podval.org/2010/01/maven-in-project-repository.html

- I installed the only instance of support library into that repo (latest version from google I had in my local Android SDK folder)

- I changed ABS dependency from com.google.android/support-v4 to local.libs/support-v4


After that I am able to use that modified ABS with any project which don't have to contain support lib jar in their libs folder. For IJIDEA I just add module dependency to Maven: local.libs/support-v4 for apk project (for apklib it's added automatically when import from pom.xml)


You can see my commit here https://github.com/EugeneWechsler/ActionBarSherlock/commit/9cc6edac3529616e3731b3e9945d525df3b47894

This solution fits well for me. In any time I can switch back to central repo (as soon as google put latest version there). 


文章来源



https://groups.google.com/forum/#!msg/actionbarsherlock/2cLR48IArck/70IfYCrr-pwJ

http://stackoverflow.com/questions/17314681/drawerlayout-is-missing-in-android-support-maven-repository

http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

http://blog.dub.podval.org/2010/01/maven-in-project-repository.html

https://github.com/EugeneWechsler/ActionBarSherlock/commit/9cc6edac3529616e3731b3e9945d525df3b47894


-------------------------------------------------------------------------------------------------------


你可能感兴趣的:(IDEA+maven使用最新版本的support-v4-r19)