Including Google AdMob SDK to use with Ant

2019-06-26 00:46发布

I'm using the (new?) AdMob SDK using instructions on this Google site. We are supposed to integrate the GoogleAdMobAdsSdk-4.0.4.jar file into our project. Problem is: how do we do this using Ant? I works fine in Eclipse (it goes automatically into the .classpath file), but with Ant it throws a lot of "cannot find" problems when ant releaseing.

Where and how do I include the reference to that jar? I suspect I should do it in build.xml, but I'm not sure how.

I copy the source folder elsewhere so it won't mess with my eclipse project folder.

// edited:

Let me be more specific: it works automatically if I just put the jar into libs folder, but I wanted to know if I could use the jar if the jar is located somewhere else. Anyway, my problem is solved... I can compile putting it into libs. I will take this as a curiosity question. No rush.

Here is .classpath file, below. Let me say it only makes a difference in Eclipse, but Ant does not seem to use it:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="src" path="/android_licensing"/>
    <classpathentry kind="lib" path="C:/Users/David/Documents/program/eclipse/GoogleAdMobAdsSdk-4.0.4.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

Ant error:

compile:
    [javac] C:\android-sdk-windows\tools\ant\main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 35 source files to C:\Users\David\Documents\program\eclipse\MyApp\9-branch\aaa\bin\classes
    [javac] C:\Users\David\Documents\program\eclipse\MyApp\9-branch\v9\src\net\myapp\ui\MainActivity.java:116: package com.google.ads does not exist
    [javac] import com.google.ads.*;
    [javac] ^
    [javac] C:\Users\David\Documents\program\eclipse\MyApp\9-branch\v9\src\net\myapp\ui\MainActivity.java:143: cannot find symbol
    [javac] symbol  : class AdView
    [javac] location: class net.myapp.ui.MainActivity
    [javac]     AdView adView;
    [javac]     ^

I've tried looking into main_rules, and I can see where it declares the libs folder as a place for jars, but still, I wondering if there is a simple way, per-project line of code to customize this.

Thanks.

1条回答
Evening l夕情丶
2楼-- · 2019-06-26 01:31

Unfortunately, this isn't easy to do, due to the way jars are processed in main_rules.xml:

<!-- Directory for the third party java libraries -->
<property name="jar.libs.dir" value="libs" />
<property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
<!-- create a path with all the jar files, from the main project and the
     libraries -->
<path id="jar.libs.ref">
    <fileset dir="${jar.libs.absolute.dir}" includes="*.jar" />
    <path refid="project.libraries.jars" />
</path>

It looks in one directory, and builds a path from all the files in there. Given that the admob jar has an embedded version number, I'd suggest you stick with keeping a copy in the project libs directory.

If you use SVN, you could use an externals definition to pull the jar into a subdirectory, and using a copy task at -pre-compile to move the latest one into libs; it all depends how many people (or machines) you're sharing the code with

I can't think of an elegant way that creates less maintenance than just copying the jar.

查看更多
登录 后发表回答