Android应用程序无法启动加入AdMob的后 [英] Android app fail to start after adding admob

查看:385
本文介绍了Android应用程序无法启动加入AdMob的后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序来实现的AdMob,但应用程序无法启动后,我加入了。

这是该活动code: <一href="http://$c$c.google.com/p/zhuang-dict/source/browse/trunk/ZhuangDict/src/cn/wangdazhuang/zdict/ZhuangDictActivity.java" rel="nofollow">http://$c$c.google.com/p/zhuang-dict/source/browse/trunk/ZhuangDict/src/cn/wangdazhuang/zdict/ZhuangDictActivity.java

在main.xml中:

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:广告=htt​​p://schemas.android.com/apk/lib/com.google.ads
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    &GT;
    &LT; RelativeLayout的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
    &GT;
        &LT;的ImageButton
            机器人:ID =@ + ID / TS
            机器人:contentDescription =@字符串/ tts_contentDescription
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentRight =真
            机器人:SRC =@机器人:可绘制/ ic_btn_speak_now
        /&GT;
        &LT;的ImageButton
            机器人:ID =@ + ID /搜索
            机器人:contentDescription =@字符串/ search_contentDescription
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_toLeftOf =@ ID / TS
            机器人:SRC =@机器人:可绘制/ ic_search_category_default
        /&GT;
        &LT; AutoCompleteTextView
            机器人:ID =@ + ID /编辑
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:可聚焦=真
            机器人:单线=真
            机器人:layout_toLeftOf =@ ID /搜索
            机器人:提示=@字符串/ edit_hint
        /&GT;
    &LT; / RelativeLayout的&GT;
    &LT;的WebView
        机器人:ID =@ + ID /结果
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
    /&GT;
    &LT; com.google.ads.AdView机器人:ID =@ + ID / AD浏览报
                     机器人:layout_width =WRAP_CONTENT
                     机器人:layout_height =WRAP_CONTENT
                     广告:adUnitId =身份识别码
                     广告:adSize =大旗
                     广告:loadAdOnCreate =真
     /&GT;
&LT; / LinearLayout中&GT;
 

解决方案

你有没有这个添加到你的清单?

 &LT;活动机器人:名称=com.google.ads.AdActivity
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
 

想通过谷歌显示在教程:

 &LT; com.google.ads.AdView机器人:ID =@ + ID / AD浏览报
                     机器人:layout_width =WRAP_CONTENT
                     机器人:layout_height =WRAP_CONTENT
                     广告:adUnitId =MY_AD_UNIT_ID
                     广告:adSize =大旗
                     广告:testDevices =TEST_EMULATOR,TEST_DEVICE_ID
                     广告:loadAdOnCreate =真/&GT;
 

该adUnitId必须是ID为您的应用程序,并设置此ID,还是你真正建立身份识别码如上面所示的code?

修改

下面是一些额外的信息,所有的似乎是,AdMob的库不捆绑到您的项目。这可能导致许多不同的原因。阅读的步骤,并得到肯定,你真的做到了这一点,如果没有,这样做的:

更新的Eclipse和Android SDK:

  1. 开启Eclipse作为管理员
  2. 去帮助 - >检查更新,并运行更新
  3. 在接下来的窗口中设置的一切检查,多数民众赞成。这不是必要的,但它不会是不妥更新所有
  4. 接受条款和许可证持有者和preSS完成......更新将启动,需要一定的时间
  5. 在重新启动Eclipse作为管理员,如果更新完毕。这可能是你得到,并非所有的更新可以做一个错误信息......前进

更新的Andr​​oid SDK:

  1. 在Eclipse中转到窗口 - > Android的SDK管理器
  2. 在列状态你看,如果更新可用与否。选择所有更新...
  3. 如果完成后,重新启动Eclipse再次

工作,Admob的 - 把jar文件,并设置路径:

  1. 在下载AdMob的SDK从谷歌网站(可以是不同的链接取决于国家) https://developers.google.com/mobile-ads-sdk/download ?HL =德
  2. 将文件解压到一个目录中(无论身在何处)
  3. 创建Eclispe的项目内的库文件夹中。 肯定的是,文件夹命名为库,而不是LIB。这个错误往往是做


  4. AdMob提供的文件夹中的jar文件复制到你的项目到libs文件夹

  5. 单击lib文件夹里面的jar文件,点击鼠标右键,选择构建路径 - >添加到构建路径
  6. 要获得确保一切都真的完成后,点击您的项目鼠标右键,选择属性
  7. 选择的Java构建路径,去图书馆标签
  8. 选择添加外部JAR,并从AdMob的文件夹中选择这个jar
  9. 选择确定

开始

  1. 要把它放到你的Manifest.xml

     &LT;活动机器人:名称=com.google.ads.AdActivity
       android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
     &LT; /用途&gt;
     

您的Manifest.xml应该类似于此:

 &LT; XML版本=1.0编码=UTF-8&GT?;
         &LT;舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
          包=com.company
          安卓版code =1机器人:VERSIONNAME =1.0&GT;
       &lt;应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME
           机器人:可调试=真正的&GT;
       &LT;活动机器人:标签=@字符串/ APP_NAME机器人:NAME =BannerExample&GT;
           &LT;意向滤光器&gt;
           &lt;作用机器人:名称=android.intent.action.MAIN/&GT;
            &LT;类机器人:名称=android.intent.category.LAUNCHER/&GT;
             &所述; /意图滤光器&gt;
       &LT; /活性GT;
      &LT;活动机器人:名称=com.google.ads.AdActivity
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
        &LT; /用途&gt;
        &LT; /舱单&GT;
 

请注意:把上面这条线下您的活动,而不是在

  1. 在manifest.xml的内部设置权限

     &LT;使用-权限的Andr​​oid:名称=android.permission.INTERNET对/&GT;
    &LT;使用-权限的Andr​​oid:名称=android.permission.ACCESS_NETWORK_STATE/&GT;
     

  2. 创建例如XML布局一样显示在教程

     &LT; XML版本=1.0编码=UTF-8&GT?;
       &LT; LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
          的xmlns:广告=htt​​p://schemas.android.com/apk/lib/com.google.ads
          机器人:方向=垂直
          机器人:layout_width =FILL_PARENT
          机器人:layout_height =FILL_PARENT&GT;
        &LT; com.google.ads.AdView机器人:ID =@ + ID / AD浏览报
                     机器人:layout_width =WRAP_CONTENT
                     机器人:layout_height =WRAP_CONTENT
                     广告:adUnitId =MY_AD_UNIT_ID
                     广告:adSize =大旗
                     广告:testDevices =TEST_EMULATOR,TEST_DEVICE_ID
                     广告:loadAdOnCreate =真/&GT;
       &LT; / LinearLayout中&GT;
     

  3. 此外,如果上面的步骤没有工作,你可以在你的活动做到这一点要显示AdMob的。请参阅您的活动,以您的AdMob的XML ID中的onCreate():

     公共类AdMobActivity延伸活动{
    
       私人AD浏览报AD浏览报;
    
        @覆盖
        公共无效的onCreate(包savedInstanceState){
            super.onCreate(savedInstanceState);
                的setContentView(R.layout.main);
    
            //创建AD浏览报
       AD浏览报=新的AD浏览报(这一点,AdSize.BANNER,MY_AD_UNIT_ID);
    
           //查找您的LinearLayout假设它是被赋予了
          //属性机器人:ID =@ + ID / mainLayout
        的LinearLayout布局=(的LinearLayout)findViewById(R.id.mainLayout);
    
           // AD浏览报给它添加
         layout.addView(AD浏览报);
    
           //初始化一个通用的请求与广告加载
        adView.loadAd(新AdRequest());
    
         }
     

在我的应用程序,我做了两个,通常只需要做到这一点在XML或code,但与这两个正常工作了。

I'm trying to implement admob in my app, but the app failed to start after I added it.

This is the activity code: http://code.google.com/p/zhuang-dict/source/browse/trunk/ZhuangDict/src/cn/wangdazhuang/zdict/ZhuangDictActivity.java

The main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    >
        <ImageButton
            android:id="@+id/ts"
            android:contentDescription="@string/tts_contentDescription"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true" 
            android:src="@android:drawable/ic_btn_speak_now"
        />
        <ImageButton
            android:id="@+id/search"
            android:contentDescription="@string/search_contentDescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/ts"
            android:src="@android:drawable/ic_search_category_default"
        />
        <AutoCompleteTextView
            android:id="@+id/edit"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:focusable="true"
            android:singleLine="true"
            android:layout_toLeftOf="@id/search"
            android:hint="@string/edit_hint"
        />
    </RelativeLayout>
    <WebView
        android:id="@+id/result"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
    <com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="myId"
                     ads:adSize="BANNER"
                     ads:loadAdOnCreate="true"
     />
</LinearLayout>

解决方案

Have You added this to Your Manifest?

    <activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

Like shown in the tutorial by google:

    <com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="MY_AD_UNIT_ID"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                     ads:loadAdOnCreate="true"/>

The adUnitId has to be the Id for Your app, did You set this ID or did You really set "myid" like in your code shown above?

EDIT

Here is some additional information, All seems to be that the AdMob Lib is not bundled to Your project. This could cause of many different reasons. Read the steps and get sure, You have really done this, if not, do it:

Update Eclipse and Android SDK:

  1. open Eclipse as Administrator
  2. go to Help-->Check for updates and run the updates
  3. set everything checked thats shown in the next window. It is not necessary but it would not be amiss to update all
  4. accept the terms and licensees and press finish...the updates will start and needs some time
  5. restart Eclipse as Admin if updates finished. It is possible that You get an error message that not all updates could be done...go forward

Update Android SDK:

  1. in Eclipse goto Window-->Android SDK Manager
  2. at the Column "Status" You see if a update is available or not. Select all updates...
  3. if finished, restart Eclipse again

Work With Admob - put jar file and set path:

  1. download AdMob SDK from Google site(could be a different link depends on country) https://developers.google.com/mobile-ads-sdk/download?hl=de
  2. unzip the file into a directory (no matter where)
  3. create a "libs" folder inside your project in Eclispe. BE SURE THAT THE FOLDER IS NAMED "libs" AND NOT "lib". THIS MISTAKE IS OFTEN DONE


  4. copy the jar file from admob folder into Your project into the libs folder

  5. click right mouse button on jar file inside lib folder and choose Build Path-->add to build path
  6. To get sure everything is really done, click right mouse button on Your project and choose properties
  7. select Java-Build-Path and go to Libraries Tab
  8. select add external jar and select this jar from your admob folder
  9. select ok

get started

  1. put this into your Manifest.xml

    <activity android:name="com.google.ads.AdActivity"
       android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
     </application>
    

Your Manifest.xml should look similar to this:

       <?xml version="1.0" encoding="utf-8"?>
         <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.company"
          android:versionCode="1" android:versionName="1.0">
       <application android:icon="@drawable/icon" android:label="@string/app_name"
           android:debuggable="true">
       <activity android:label="@string/app_name" android:name="BannerExample">
           <intent-filter>
           <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
             </intent-filter>
       </activity>
      <activity android:name="com.google.ads.AdActivity"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
        </application>
        </manifest>

NOTE: Put this line above under Your activity, not inside

  1. set permissions inside the manifest.xml

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    

  2. create the xml layout for example like shown in the tutorial

    <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
        <com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="MY_AD_UNIT_ID"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                     ads:loadAdOnCreate="true"/>
       </LinearLayout>
    

  3. Additionally, if the steps above did not work, You could do this inside Your Activity where You want to show the admob. Refer to Your admob xml id in onCreate() of Your Activity:

        public class AdMobActivity extends Activity {
    
       private AdView adView;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
    
            // Create the adView
       adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
    
           // Lookup your LinearLayout assuming it’s been given
          // the attribute android:id="@+id/mainLayout"
        LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
    
           // Add the adView to it
         layout.addView(adView);
    
           // Initiate a generic request to load it with an ad
        adView.loadAd(new AdRequest());
    
         }
    

In my App, I have done both, usually it is only necessary to do it in XML or Code, but with both it works fine too.

这篇关于Android应用程序无法启动加入AdMob的后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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