Trouble adding Admob 6.2.1 SDK to my project - java

I was developing an application on API 9, 2.3.3 then I changed the build to 4.0.3 because I only had 4.0.3 installed other than 2.3.3 and 2.2 due to admob's policy.
I have tried to embed admob into my Android application but have been failing ever since. I finally did it on my school computer and it works perfectly. However, I imported my project into my own laptop, trying to edit and add on more coding and lots of problems started to arise without even editing any part of the code.
What I know is that my school PCs are using eclipse indigo and I am using juno.
Is it because I did not import my codes properly or it is my eclipse version or something else?
Here's the dummy code I did.
MainActivity.Java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
XML
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="the right code"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
Manifest
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
So there is it. I have looked into many sites for help but to no avail.

When you move a project in between computers you have to re-import things (because their file path's have changed). Try looking in your imports and seeing if the SDK is still imported.
Whether it is or not, if you are using ADT tools r-17 and up then you have to create a libs/ folder in you main directory, and put a copy of the adMob SDK in there.
Hope this solves your problem

Check for updates and installed sdks in your sdk manager in eclipse and check if the admob sdk for your target is installed.
and do not forget to set your application target to google apis x.y

Related

Android successful built gradle but not install apps on emulator

I was having some problem with Android Architecture Component. What I am trying to do is from the view model, I will execute the functions inside repository class. Here is my view model:
private final ReservationRepository reservationRepository;
private final UserRepository userRepository;
private LiveData<List<ReservationEntity>> reservations;
#Inject
public ReservationViewModel(ReservationRepository reservationRepository, UserRepository userRepository) {
this.reservationRepository = reservationRepository;
this.userRepository = userRepository;
reservations = reservationRepository.loadReservations();
}
public LiveData<List<ReservationEntity>> getAllReservations() {
return reservations;
}
Then in my repository class:
private final ReservationDao reservationDao;
#Inject
public ReservationRepository(ReservationDao reservationDao) {
this.reservationDao = reservationDao;
}
public LiveData<List<ReservationEntity>> loadReservations() {
return reservationDao.getAllReservation();
}
In my DAO class:
#Query("SELECT * FROM reservation")
LiveData<List<ReservationEntity>> getAllReservation();
I got one AppModule to #Provide the #Inject:
#Provides
#Singleton
ReservationDatabase provideReservationDatabase(Application application) {
return Room.databaseBuilder(application,ReservationDatabase.class,
ReservationDatabase.DATABASE_NAME).allowMainThreadQueries().build();
}
#Provides
#Singleton
ReservationDao provideReservationDao(ReservationDatabase reservationDatabase) {
return reservationDatabase.reservationDao();
}
I managed to build the project successfully. However, after successfully built gradle, it does not install the apps onto the emulator. Any ideas?
Thanks!
In my case, a Gradle Sync solved the issue.
You can do the following to resolve your problem
You can turn off the instant Run.
File>Settings>Build , Execution , Deployment>Instant Run>Uncheck the Instant Run.
After that try to run your app on emulator again.
Restart Android studio
File->Invalidate Caches / Restart
Perform Clean Build
Build->Clean Project
Try to Sync your project
File-> Sync project
Make sure Project location does not contain the special character.
E:\Android_Projects\T&PUIET,KUK\app\build\outputs\apk\app-debug.apk
close android studio > rename folder containing the special character(here T&PUIET,KUK ) > restart android studio.
Hope this Solution helps!
As #David Miguel Say that just do sync project with Gradle.
I do my problem solved.
Just use All search in my case Linux then I do double Shift press.
in my "dumb - case" i didn't have a launcher activity, add this to the first one :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Try using Make Project option under Build.
1.In Android Studio go to Build>Build APK(s)
Then find the apk file of your app at
[project-location]\app\build\outputs\apk\debug
2.Open command prompt or terminal(for MAC) of your PC and type
cd C:\Users[user-name]\AppData\Local\Android\Sdk\platform-tools
It may vary if location of your installed SDK is different.
3.Then copy paste the generated apk in step1 at the location in step2.
Then run adb install [generated apk name]
This should install apk in your emulator. Just make sure no other device is connected and no other emulator is running other than where you want to install it.
Behavior changes: Apps targeting Android 12!
Warning: If an activity, service, or broadcast receiver uses intent
filters and doesn't have an explicitly-declared value for
android:exported, your app can't be installed on a device that runs
Android 12.
In my case (on physical device) I had to change android:exported from false to true in AndroidManifest.xml othervice device is not able to open app installed by android studio (app icon appears on devie but clicking = app isnt installed)
<manifest ...>
<application ... >
<activity ... android:exported="true" >
In my case, syncing Gradle and other answers didn't help. Because my problem was pretty idiotic. I didn't let the android studio to generate MainActivity when creating the project, so I had to generate the class and the layout manually. But I misplaced assigning the MainActivity to manifest file using the the tag <activity... </activity>

Android Studio 2.1 Cannot resolve symbol 'R'

Android Studio 2.1,
Java V8 Update 91, Gradle 2.1.0 .
I know that this questions has been asked many times here, but none of the recommendation solutions works out.
In a sudden after compiling ready to run on Emulator, my IDE give an error at the R.id attribute. Every Java files suddenly give the same error even I don't make any changes to the file.
I tried to make a new project, see if things different but the error keep coming. In my mind it could be internal error, again. Even I just update my IDE just now.
The Java file;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_science);
list_View = (ListView) findViewById(R.id.maintable);
String[] Days = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday"};
dayList.addAll(Arrays.asList(Days));
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, dayList);
list_View.setAdapter(adapter);
NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
if (nfc.isEnabled()) {
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, dayList);
Toast.makeText(this, "NFC turned ON", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(this, "Please turn On NFC", Toast.LENGTH_SHORT).show();
}
}
The R is the error.
XML file that associate to the Java;
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/maintable"
>
</ListView>
Is this, again, an internal error?
Try syncing the project, go to Tools > Android > Sync Project with Gradle Files
UPDATE
If you're using Android Studio 3.3, use the Sync Project with Gradle Files icon
I have just gone through this nightmare. Ended up removing all xml code to notepad until it was fixed. Then reintroduced sections of code until problem appeared.
Thinking back, it all started when I pasted some code using WordPad. Apparently WordPad contains a different coding or something so bet to avoid.
Anyway just check your white space in xml by deleting it all to rid yourself of any hidden characters.
Try performing a clean and rebuild by going to Build > Clean Project and Build > Make Project
Sometimes the R.java class is not created when there is some error into an xml file (like activity_main.xml). For example, if you change some attribute name that has a reserved word that cannot be changed.
Like this: if you changed the attribute called: id to another name like
id_A_Word_With_Error_Here in this code that can be part of the activity_main.xml, your error (R class not created) can occur.
<android.support.v7.widget.RecyclerView
android:id="#+id/messageRecyclerView"
and there is an error like:
<android.support.v7.widget.RecyclerView
android:id_A_Word_With_Error_Here="#+id/messageRecyclerView"
If clean, rebuild did not work and there is no error with import like import com.something... , my suggestion is to search an error into xml files.
I've seen this problem many times. The right solution is:
When you type R, the Android Studio will give you many different namespaces for R to choose from, that look like R(***.***.***), but what you really need is the namespace that ends with ***.myProject. (Note: myProject is your project name), e.g: R(com.example.milka.demoProject).
If you choose any other namespace, you will get the error message, so you have to delete the unneeded import, and re-choose your R
I try to change the Gradle version from 2.1.0 to 2.0.0, even in AS ver 2.1, ignoring the Instant Run performance and its work out. The little R error is now gone. Now, I tried to change back to 2.1.0, the R error also gone..!!
Sometime this little thing drive me crazy, a bit.
Shame on me.
Maybe the error may cause for the tools, trying install Android SDK Build Tools from Tools > Android > SDK Manager.
or maybe this error can be caused by adding an activity to a namespace that is different to the root, you can trying >>Import com.example.MyApplication.R;
or your also can clean o rebuild your project in Build > Clean Project or Build > Rebuild Project
If you are using google play services and your compilesdk version is lower than 23 then download the new sdk and update your compile version. After that try cleaning and rebuilding. It will be fixed
Have you tried Rebuild Project go to
Build> Rebuild Project
and perform it without doing the Clean project
I had the same problem & it worked for me

An errors in the markers - Android, eclipse

I am getting a new errors and a warning after that for the same application!
Some general advices for those warnings:
These errors look like you can solve them by choosing project > clean from the menu or simply by restarting eclipse (please try both). Also have a look at AndroidManifest.xml.
There should be lines which looks something like this:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
Set minSdkVersion to an API level you want to support at least. Nowadays, this is API level 8 in most cases, if you want to support very old devices, set it to 4 or something. targetSdkVersion should be set to the android version of your test device you use for development. Also, be aware you need to download the matching sdk (in this case API level 18) through Android SDK Manager which you can find in the Window menu entry of eclipse.
Make sure you have The correct build target set in eclipse: right click project > properties > Android > Project Build Target should have a correct check.

Media is not defined - How do I enable Media in a PhoneGap app in Eclipse

I'm developing an application using PhoneGap in Eclipse and whenever I use the Media object I get an exception on this line:
var test = new Media("/android_asset/www/sound/music/Weird.mp3", null, null, null);
12-31 13:52:56.775: E/Web Console(3688): Uncaught ReferenceError:
Media is not defined:25
This exception is, supposedly, due to the fact that I haven't implemented the Media plugin. I just upgraded from 2.9 to 3.3 so there were some changes with the new plugin-system that I haven't used before.
I tried to follow the instructions in the PhoneGap Media documentation but it kept refering to the use of their Command Line Interface. I'm working in Eclipse and I have created the entire project in eclipse, built the Cordova-3.3.0.jar file myself and then added it to the project. Everything works fine up until the use of the Media object.
Anyone have any idea how to add support for Media to a PhoneGap 3.3.0 project? Can I use the CLI on a project created in Eclipse?
I tried to just add support for it by adding the following to my res/xml/config.xml file:
<feature name="Media">
<param name="android-package" value="org.apache.cordova.AudioHandler" />
</feature>
and then adding the proper permissions in my AndroidManifest file:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
but that didn't work very well either. Any help would be greatly appreciated!
Right. The problem was that I created my Eclipse project using only the Cordova-3.3.0.jar file I had manually built from the source. I should've just created the project using the Command Line Interface as the manual clearly states, added the Media (also through the CLI) and then imported the entire project into Eclipse using File => New => Other => Android from Existing Source.
I got it working now doing it as I described above, hopefully this might help someone some day :P

R.id cannot be resolved [duplicate]

This question already has answers here:
R cannot be resolved - Android error
(108 answers)
Closed 10 years ago.
So I copied this tutorial example thing right from Google's android site and I ma getting an error that R.id cannot be resolved.
Here is my Java file
package com.TestApp.HelloWebView;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class HelloWebView extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
}
}
Here is my res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
You have to import your R class
import com.TestApp.HelloWebView.R;
Also as Demand posted you have to use a namespace for your layout.
?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
I had the same problem when I updated my Android SDK. Suddenly new projects could not generate the R.java file.
importing my R.java didn't help because it wasn't generated
cleaning and building the project didn't help either -- the /gen folder was still empty.
I found that after the upgrade, the adb server didn't start up properly. So a manually started it:
$ cd $ANDROID_SDK/platform-tools
$ adb start-server
Then I restarted Eclipse and did a clean/build on the project, which generated the R.java file.
If using Eclipse, run a clean build (Project/Clean...); this can often clear issues with the resources not being compiled correctly.
Did you try any of the solutions listed here?
R cannot be resolved - Android error
Also, look for your R.java file. Are there any errors with it?
I had this problem too. I can't say a solution in general, but you can make a new workplace and copy the hardcode. In the future never click on clean or build, instead save or start eclipse again.
Go in your main.xml file, delete a char and rewrite it. That will generate the R file again.
On trying an Android beginner's tute (http://mobile.tutsplus.com/tutorials/android/android-sdk-development/) the "R.id cannot be resolved" error had me stumped too. In my case it was an android:onClick in /res/layout/main.xml. It seems onClick is not supported in AVD platform 1.5 API level 3.
A change to a new AVD with platform 1.6 API, level 6 removed the error - also started the project from scratch with the new api and level settings. For absolute Eclipse newbies (like myself) create a new AVD with:
Window -> Android SDK and AVD Manager -> New. Select platform, level number from "Target" drop down list.
Also try deleting the ~.android\debug.keystore (Happened to me, thought it was due to R.id issue). Real problem was debug.keystore was older than a year!
I ran into this problem when I tried to follow Lars Vogel's Android development tutorial...it turns out my problem is simply because I didn't save the layout file. Once I save the file, it works fine.
make sure you do not have any xml files with capitals in the name.
I had the same problem.
all the file names in res (and all its sub folders including layout) must be lower case only. This includes image files, xml files, etc (even if they aren't referenced anywhere within the project.)
if you posted full your main.xml file, then it's not right. You must write a namespace of xml:
xmlns:android="http://schemas.android.com/apk/res/android"
for example:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/label"
android:layout_width="78dip"
android:layout_height="65dip"
android:paddingTop="4dip"
android:textSize="12dip"
android:singleLine="true"
android:ellipsize="end"
android:textColor="#color/bright_text_dark_focused"
android:gravity="center_horizontal|center_vertical" />
Yeah another fix
I started the emulator. By running a helloandroid program, that did compile.
And got out of eclispe and got back in don't know which one fixed the problem..
Cleaning the project etc didn't fix it - can i have 2 hrs of my life back!
import com.TestApp.R;
isn't accepted once R is lost.
My Eclipse now auto creates a new "res" folder everytime I "clean". Yes, I have two folders named "res" in parallel directly under my project folder. The auto created one is empty. String values are still found. No other errors than "R cannot be resolved" are reported by Eclipse.
Eureka! I've managed to make my first android project import to Eclipse!
Earlier I always got "Unable to find system library" under the project's Properties - Java build path - Libraries tab and it was impossible to correct it once it occured. The consequence was that no import statements could be resolved by anything imported.
In this case, I changed the JDK compliance level from 1.6 to 1.5 BEFORE I imported (afterwards its too late and cannot be mended). It must be done from Window - Preferences - Java - Compiler (earlier I thought this option was available only by right-clicking on already imported project). Then right-click on each project and set Properties - Android to a suitable Target (with the errors above, eclipse ignores any selection here). Then, I could even change back to JDK compliance level 1.6.
So, in general, changing the JDK compliance level before importing, might help.
And when deleting a project ALWAYS check the "Delete project content on disk (cannot be undone)" checkbox in the "Are you sure" dialog. Otherwise it is impossible to re-import the project, o if you've imported it with the wrong JDK compliance level the first time, it is impossible to correct the mistake, other than to try in another workspace.
These are the experiences of a very frustrated Eclipse user.
Make sure there is not a hidden error in one of your .xml files.
Sometimes you can delete a statement in the strings.xml file that is important.
For example, in the Vogella example, I got the error:
Error: No resource found that matches the given name (at 'title' with value '#string/menu_settings').
I had deleted the line:
<string name="menu_settings">Settings</string>
Putting this back in or deleting res/menu/main.xml would solve the error.
I had the same problem but got fixed
i dont know exactly how this problem gonna fix
Just try, It might be helpful
add this code at the top of ur code
import com.MyFirstApp.activities.R;
here com.MyFirstApp.activties is my component name replace it with your component name

Categories

Resources