Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Distant-Object · May 05, 2014 at 09:52 PM · androidpluginandroidpluginandroid-manifestmanifest

How to alter the Android Manifest to use my ad-displaying activity in Unity?

So I successfully compiled an android application that displays an ad: ![Android app with an ad][1]

Now, I want to use this in my android game. To do so, I take the following steps;

  1. In eclipse, label my project as a library, which makes a jar

  2. Replace public class BannerSample extends Activity { with public class BannerSample extends UnityPlayerActivity { (and add import com.unity3d.player.UnityPlayerActivity;)

  3. Remove setContentView(R.layout.activity_main);

  4. Now back in Unity, I put my newly created bannersample.jar in the Plugins/Android folder, along with the jars my app requires: android-support-v4.jar, classes.jar, google-play-services.jar

Finally, I need to create an Android Manifest in this folder to tell it to use my activity. As a starting point, I go to Temp/StagingArea in my game's directory, where I find the basic Manifest that it generates. Initially it looks like this:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gms.ads.banner" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
   <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
   <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
     <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait">
       <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
       <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
     </activity>
   </application>
   <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
   <uses-feature android:glEsVersion="0x00020000" />
 </manifest>

Here is the manifest for my ad-display app:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="com.google.example.gms.ads.banner"
           android:versionCode="1"
           android:versionName="1.0">
     <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
     <uses-permission android:name="android.permission.INTERNET"/>
     
     <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:allowBackup="true">
         <activity android:name=".BannerSample" android:label="@string/app_name">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
         
         <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
         <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
     </application>
     
 </manifest>
 

However, no matter what I do, no combination of the two files work. And this is where I really need help. How do I merge these two files together? Adding the user permission is no problem, however I cannot get correct activity lines.

If I replace

android:name="com.unity3d.player.UnityPlayerNativeActivity">

with

android:name=".BannerSample">

Unity tells me this when I try to compile: ` Unable to find unity activity in manifest. You need to make sure orientation attribut is set to portrait manually. UnityEditor.HostView:OnGUI()

In addition, as you can see in my app's manifest, I have the following two lines:

     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

If I include the second line anywhere (meta-deta) then Unity fails to build my app everytime, giving me the following error:

Error building Player: CommandInvokationFailure: Failed to re-package resources. See the Console for details.

C:\Users\Owner\Development\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk\build-tools\android-4.4.2\aapt.exe package --auto-add-overlay -v -f -m -J gen -M AndroidManifest.xml -S "res" -I "C:/Users/Owner/Development/adt-bundle-windows-x86_64-20140321/adt-bundle-windows-x86_64-20140321/sdk/platforms/android-19\android.jar" -F bin/resources.ap_ With the exception of the above error, Unity will build the app but it will quit as soon as started. I have tried every combination of the two files in regards with the activities. I have even tried removing some of the jars. Please help, how do I successfully merge these two files? What activities do I include and exclude, and why? [1]: /storage/temp/26194-workingad.png
workingad.png (98.5 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make an Android plugin for unity? 0 Answers

[URGENT!]Android Manifest file keeps reverting changes after build! 0 Answers

How do I use a custom Android Manifest? 2 Answers

How to extend UnityPlayerActivity 0 Answers

Starting a activity in Android Library 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges