I am building an android application that has two versions.One with Ad. and one with out Ad. . I've successfully integrated the AdMob in the application. but the Ads are not getting displayed on the screen.
Here's my
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors{
free{
applicationId "com.myapp"
buildConfigField "boolean","IS_PAID_VERSION", "false"
}
paid{
applicationId "com.myapp.paid"
buildConfigField "boolean","IS_PAID_VERSION", "true"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-ads:8.4.0'
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.myapp.activities.AdTestActivity">
<com.google.android.gms.ads.AdView
android:id="#+id/ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/ad_unit_id" />
</RelativeLayout>
AdTestActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.myapp.R;
public class AdTestActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ad_test);
final AdView adView = (AdView) findViewById(R.id.ad_view);
final AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("A144A6A159A94CC77CE70EC1A874B93A") //My test device 1
.addTestDevice("8477FA9B6C105C84897FC2717E19A548") //My test device 2
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
adView.loadAd(adRequest);
}
}
The ad is no getting displayed on the screen, and the logcat says...
I/Ads: Starting ad request.
02-12 00:24:41.381 15472-15493/com.myapp W/Ads: There was a problem getting an ad response. ErrorCode: 2
02-12 00:24:41.382 15472-15472/com.myapp I/Ads: Scheduling ad refresh 60000 milliseconds from now.
02-12 00:24:41.382 15472-15472/com.myapp W/Ads: Failed to load ad: 2
PS: I've a good internet connection and valid AdUnitId. I don't have any kind of AdBlock applications in my device. I've also read all SO threads about this problem, but none of them worked for me.
What am i doing wrong here ? :(
I had the same issue and I fixed it by updating Google Play Services to the latest version on my mobile. So maybe try updating it from Play Store.
Related
I am currently refreshing my android developement skills and came across the CalendarView component. I wanted to disable the scrolling of the calendar and instead enable the arrows to browse through the calendar.
What I want to know is the following:
How can I disable the scrolling from the CalendarView? And why does Android Studio show me the arrow browse-version in the Designer-Mode but compiles and runs the scroll-version of the calendar?
I am running an Android VM, a "Galaxy Nexus" with API 22. I also posted the "build.gradle" further below.
What Android shows me/What I want:
What Android Studio compiles & runs:
Here some code:
// activity_main.java:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="0dp">
<CalendarView
android:id="#+id/calendarView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
// build.gradle
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.kalender003_emptyactivity"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Use MaterialComponents Theme, it will most probably solve the issue.
In your values/themes file replace the parent them with this,
parent="Theme.MaterialComponents.DayNight.DarkActionBar"
If you don't want Action Bar then ,
parent="Theme.MaterialComponents.DayNight.NoActionBar"
And if you only want to show Light Coloured Calendar view regardless of Devices's theme use,
parent="Theme.MaterialComponents.Light.NoActionBar"
Thanks to Vaibhav Goyal i came across the solution.
The API level I used was to low (API 22, Android 5.1). Changing that to API 23 (Android 6.0) solved my problem. Now it shows me the CalendarView with arrow-navigation instead of the scroll version!
yourCalenenderId.addOnItemTouchListener(object : RecyclerView.SimpleOnItemTouchListener() {
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
return if (e.action == MotionEvent.ACTION_MOVE) {
true
} else {
super.onInterceptTouchEvent(rv, e)
}
}
})
My problem is that I am not able to use CoordinatorLayout in Android Studio despite adding all the possible dependencies in my build.gradle file. The class is not instantinated.
Here's my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.uiuxpractical4materialdesign"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
The Error:
java.lang.NoClassDefFoundError: androidx/coordinatorlayout/R$attr
at androidx.coordinatorlayout.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:211)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:403)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:186)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:144)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:309)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:418)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:429)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:333)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:323)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:394)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:200)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:572)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$5(RenderTask.java:698)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Due to this, the class is not instantinated and I get something like this:-
Also, here a small picture of the error too:-
Thanks for everyone helping out there to solve this issue.
Please also inform if you need anything else.
try to add this line in your dependencies in build.gradle
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:design:29.0.2'
don't worry about the difference between com.android..... and androidx.... This implementation androidx. automatically migrate the implementation if your android studio is higher than 3.2.
you can check this link.https://stackoverflow.com/a/58619780/10075771 it will help you understand also the situation :)
Hoping i help you in little way :)
try adding below dependencies
implementation 'com.android.support:appcompat-v7:23.1.1'
implementation 'com.android.support:design:23.1.1'
Hope this will work for you.
I'm creating a new android project with SDK 28 when project finished to create I have an error in MainActivity.
I tried some methods:
Clean project
Clean Android Studio cache
Clean Gradle cache
Re-installed IDE
File-> Invalidate cache/restart
Remove .idea folder
Restart Android Studio.
Android Studio About:
Android Studio 3.3.2
Build #AI-182.5107.16.33.5314842, built on February 15, 2019
JRE: 1.8.0_152-release-1248-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.israteneda.myapplicationtest2"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
MainActivity.java
package com.israteneda.myapplicationtest2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
The error showed is:
Android resource linking failed
error: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.israteneda.horariu:style/Theme.AppCompat.Light.DarkActionBar) not found.
D:\israt\android_apps\HorariU\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:173: error: style attribute 'attr/colorPrimary (aka com.israteneda.horariu:attr/colorPrimary)' not found.
D:\israt\android_apps\HorariU\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:174: error: style attribute 'attr/colorPrimaryDark (aka com.israteneda.horariu:attr/colorPrimaryDark)' not found.
D:\israt\android_apps\HorariU\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:175: error: style attribute 'attr/colorAccent (aka com.israteneda.horariu:attr/colorAccent)' not found.
error: failed linking references.
When I change the SDK to 27 the MainActivity works.
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.israteneda.horariu"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
MainActivity.java
package com.israteneda.myapplicationtest2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Also works with androidx library.
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.israteneda.myapplicationtest"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
MainACtivity.java
package com.israteneda.myapplicationtest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I expect to create an android project without problems, but the actual output is an error with AppCompatActivity on MainActivity. Why does this problem happen?
I got the same issue and solved it by updating Android Studio
1.Go to your project directory (or to Project View)
2.Find and open .idea directory
3.Remove caches and libraries directories
4.Invalidate Caches / Restart
The problem was solved by updating the new version of android studio 3.4, without importing the settings of the previus version.
Tried Many Solution But No Helped
Ref : Failed to find style 'coordinatorLayoutStyle' in current theme
But not Helped
Render Problem:
Failed to find style 'coordinatorLayoutStyle' in current theme
Tip: Try to refresh the layout.
build.gradle file of my project is :
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
module:app
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "*****"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:28.0.0-alpha1'
}
main Activity XML code
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.bottomappbar.BottomAppBar
android:id="#+id/bar"
style="#style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:navigationIcon="#drawable/ic_menu"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:fabAttached="true"
app:backgroundTint="#color/colorPrimary"
app:fabCradleVerticalOffset="12dp"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/bar"/>
</android.support.design.widget.CoordinatorLayout>
Why I am Not changing compiled SDK version 28 to 27
bcz I want to use Bottom app bar
Bottom App Bar Material Design
App Bars:Bottom- Material Design
This is a bug in 28.0.0 and the only fix(workaround) is adding this to your Build.gradle:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "27.1.1"
}
}
}
}
Which somehow, this bypasses the issue and uses 27 support library for that. Otherwise, you may wanna update your Android Studio to canary channel version or using backward support library like 27.1.1 or etc.
This error was occurred in your Rendering Layout which is a part of Studio Not in any files or Library
Try adding "Base" before Theme in styles.xml as show : -
"Base.Theme.AppCompat.Light.DarkActionBar"
Please restart Android Studio by selecting the menu option "File" →
"Invalidate Caches / Restart"
Workarounds: Try rendering with M preview using AS v1.3 preview OR
use FrameLayout for designing and change to
android.support.design.widget.CoordinatorLayout while debugging.
I just downloaded Android Studio and have created a new project.
Right off the bat, I'm getting two errors:
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.
Here is my gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.test.testapp"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
}
and my installed packages:
What is messed up here? Thanks
In your gradle, compileSdkVersion is 22 while your support library version is 23. The two should match.
See Error retrieving parent for item: No resource found that matches the given name after upgrading to AppCompat v23
I also had same problem now. I tried below steps and worked perfectly.
In .gradle change like this
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v13:23.0.1'
}
You'll get error in style file change it as below
<style name="AppTheme">
<!-- Customize your theme here. -->
</style>
modify your main_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="#+id/action_settings" android:title="#string/action_settings"
android:orderInCategory="100" android:showAsAction="never" />
</menu>
In MainActivity remove AppCompatActivity like
MainActivity extends Activity