包括与 Ant 一起使用的 Google AdMob SDK [英] Including Google AdMob SDK to use with Ant

查看:33
本文介绍了包括与 Ant 一起使用的 Google AdMob SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用(新的?)AdMob SDK,使用说明此 Google 网站.我们应该将 GoogleAdMobAdsSdk-4.0.4.jar 文件集成到我们的项目中.问题是:我们如何使用 Ant 做到这一点?我在 Eclipse 中工作正常(它会自动进入 .classpath 文件),但是使用 Ant 时它会在 ant 发布ing 时抛出很多找不到"问题.>

在哪里以及如何包含对该 jar 的引用?我怀疑我应该在 build.xml 中执行此操作,但我不确定如何执行.

我将源文件夹复制到别处,这样它就不会弄乱我的 eclipse 项目文件夹.

//已

让我更具体一点:如果我只是将 jar 放入 libs 文件夹,它会自动工作,但我想知道如果 jar 位于其他地方,我是否可以使用该 jar.总之,我的问题解决了...我可以编译把它放入库.我会将此视为一个好奇的问题.不着急.

下面是 .classpath 文件.让我说它只在 Eclipse 中有所不同,但 Ant 似乎没有使用它:

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

蚂蚁错误:

编译:[javac] C:\android-sdk-windows\tools\ant\main_rules.xml:384: 警告: 'includeantruntime' 未设置,默认为 build.sysclasspath=last;为可重复构建设置为 false[javac] 编译35个源文件到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: 包 com.google.ads 不存在[javac] 导入 com.google.ads.*;[javac] ^[javac] C:\Users\David\Documents\program\eclipse\MyApp\9-branch\v9\src\net\myapp\ui\MainActivity.java:143:找不到符号[javac] 符号:类 AdView[javac] 位置:类 net.myapp.ui.MainActivity[javac] AdView adView;[javac] ^

我已经尝试查看 main_rules,我可以看到它在哪里将 libs 文件夹声明为 jars 的位置,但我仍然想知道是否有一种简单的方法,每个项目的代码行来自定义它.

谢谢.

解决方案

不幸的是,这并不容易,因为在 main_rules.xml 中处理 jars 的方式:

<property name="jar.libs.dir" value="libs"/><property name="jar.libs.absolute.dir" location="${jar.libs.dir}"/><!-- 创建一个包含所有 jar 文件的路径,来自主项目和图书馆 --><path id="jar.libs.ref"><fileset dir="${jar.libs.absolute.dir}" includes="*.jar"/><path refid="project.libraries.jars"/></路径>

它在一个目录中查找,并从那里的所有文件构建一个路径.鉴于 admob jar 具有嵌入式版本号,我建议您坚持在项目 libs 目录中保留一份副本.

如果您使用 SVN,您可以使用外部定义将 jar 拉入子目录,并在 -pre-compile 使用复制任务将最新的移动到库中;这完全取决于您与多少人(或机器)共享代码

我想不出一种优雅的方式,比仅仅复制 jar 可以减少维护.

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.

解决方案

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.

这篇关于包括与 Ant 一起使用的 Google AdMob SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆