Can I use the AdMob SDK jar as a dependency in my maven android project?

删除回忆录丶 提交于 2019-12-07 11:24:09

问题


I'm just switching my build process to use maven, I can't find the dependency for AdMob on the maven repository site, how can I configure it manually?

Such as :

<dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>2.2.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

回答1:


An easy way to do this is to have the lib in your source tree and use this:

...
<dependency>
  <groupId>some_admob_groupid</groupId>
  <artifactId>admob</artifactId>
  <version>admob_version</version>
  <scope>system</scope>
  <systemPath>${basedir}/lib/admob.jar</systemPath>
</dependency>
...

Of course you need to change the groupId, artifactId, version and systemPath to suit your needs but this approach lets you have a local .jar in your pom.xml as a dependency without installing it to your repository.




回答2:


I saw this still didn't have the answer OP originally wanted, so despite it being a bit older, here's for future Googlers:

Download the jar from https://developers.google.com/mobile-ads-sdk/download

Put this in your pom.xml (with the appropriate version of course):

<dependency>
    <groupId>com.admob.android</groupId>
    <artifactId>ads</artifactId>
    <version>6.4.1</version>
</dependency>

And then run this on your shell, again with the appropriate version/jar name:

mvn install:install-file -Dfile=GoogleAdMobAdsSdk-6.4.1.jar -Dversion=6.4.1 -DartifactId=ads -DgroupId=com.admob.android -DgeneratePom=true -Dpackaging=jar

Mind you that the above command has the version that you need to change in two places - once in the filename, and once in the -Dversion parameter.

It might also be a good idea to include the latest version of the library in your project and have something like the following in your pom.xml above the dependency, as this isn't a step you are likely to remember if you had to google it ;)

<!--  If you just set up your dev system and the following dependency gives you an error,
    run these commands:

    cd project-root
    mvn install:install-file -Dfile=libs/GoogleAdMobAdsSdk-6.4.1.jar -Dversion=6.4.1 -DartifactId=ads -DgroupId=com.admob.android -DgeneratePom=true -Dpackaging=jar

-->


来源:https://stackoverflow.com/questions/5146622/can-i-use-the-admob-sdk-jar-as-a-dependency-in-my-maven-android-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!