Run Lollipop version apps to lower version apps such as API 8? - android-studio

I am very new to Android Studio! I have done phone contacts with the help of card views. I could be able to see output on Emulator (version 21) which I have run app on 21. But now I just need to run lolipop (API 21) version apps on lower version devices like (API 8).
If it runs then can be able to download APK to lower version devices which supports only API 8. The material design and themes should not be changed like I have on API 21. I have added cardView and recycler view libraries to support. Do I need to change or add any other things?
In Build.gradle,
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.meenar.meen_app3"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
}
In Android Manifest.xml,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.meenar.meen_app3"
xmlns:tools="http://schemas.android.com/tools">
<uses-sdk
tools:node="replace" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
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=".Card1Activity">
</activity>
<activity
android:name=".Card2Activity">
</activity>
<activity
android:name=".Card3Activity">
</activity>
<activity
android:name=".Card4Activity">
</activity>
<activity
android:name=".Card5Activity">
</activity>
</application>
In Styles.xml, ie. values-v21 :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material">
</style>
</resources>
When I run on API 21 version, it has material design effects - Checkboxes and radiobuttons of cardview:

Related

Razorpay implementation error in Android Studio

I have implemented Razorpay-checkout,
but when I clicked build it shows only manifest error, I tried many times, but it always shows an error, I have attached some code please help me. I have seeing this type error
Manifest merger failed : android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined
Gradle
plugins {
id 'com.android.application'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.razopay"
minSdk 21
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
targetSdkVersion 31
minSdkVersion 21
}
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.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'com.razorpay:checkout:1.6.12'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Build Error
Manifest merger failed : android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.razopay">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Razopay">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The solution is to override manifest settings of razorpay.
Add below lines in your AndroidManifest.xml file in order to override manifest settings of razorpay.
<receiver
android:name="com.razorpay.RzpTokenReceiver"
android:exported="false">
<intent-filter>
<action android:name="rzp.device_token.share" />
</intent-filter>
</receiver>
<activity
android:name="com.razorpay.CheckoutActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:exported="true"
android:theme="#style/RazorpayTheme"
tools:replace="android:theme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<data
android:host="rzp.io"
android:scheme="io.rzp" />
</intent-filter>
</activity>
and We also have to replace the theme of CheckoutActivity in order to resolve further crashes,
tools:replace="android:theme
tag is important here, which has been mentioned above in manifest settings, now add below code to styles.xml.
<style name="RazorpayTheme" parent="Theme.AppCompat.Dialog">
<item name="android:windowActionBar">false</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:windowCloseOnTouchOutside">false</item>
</style>

ERROR: Manifest merger failed : Attribute application#appComponentFactory

I have issue an with gradle build in Android Studio . When I add Admob Activity in the project, while adding the dependencies to the project it throws Two errors
ERROR: Manifest merger failed
org.gradle.execution.MultipleBuildFailures: Build completed with 1 failures
For 1st issue , it suggests like " Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:10:5-32:19 to override.
"
Even after adding tools: replace="android:appComponentFactory" to Androidmanifest gradle sync fails
AndroidManifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.ani.admobcheck">
<!-- Include required permissions for Google Mobile Ads to run. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".Ads"
android:label="#string/title_activity_ads"></activity>
<!-- Include the AdActivity configChanges and theme. -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiM ode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Build.gralde :
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.ani.admobcheck"
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'
implementation 'com.google.android.gms:play-services-ads:18.0.0'
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'
}
I got Sync error as :
ERROR: Manifest merger failed : Attribute
application#appComponentFactory value=
(android.support.v4.app.CoreComponentFactory) from
[com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0]
AndroidManifest.xml:22:18-86 value=
(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to
<application> element at AndroidManifest.xml:10:5-32:19 to override.
I tried adding tools:replace="android:appComponentFactory" in AndroidManifest
I had similar problem. Added two lines in gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
These two lines automatically resolved my dependency conflicts between google's files and third party dependencies.
Find a solution by adding googlePlayServicesVersion = "16.+" to app/build.gradle, since Google Services has been updated :
buildscript {
ext {
...
googlePlayServicesVersion = "16.+"
}
...
}

Toolbar doesn't show in android studio preview

Android toolbar doesn't show in android studio,but it's shown on the device. I tracked so many topics but there is no specific solution.I create a new project on android and It's not shown anyway.Also it doesn't show my old projects.
device
Also I get those errors
Render Problem
Failed to load AppCompat ActionBar with unknown error. Tip: Try to refresh the layout.
Failed to instantiate one or more classes
The following classes could not be instantiated:
- android.support.v7.widget.ActionBarContainer (Open Class, Show Exception, Clear Cache)
- android.support.v7.widget.ActionBarContextView (Open Class, Show Exception, Clear Cache)
- android.support.v7.app.WindowDecorActionBar (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.
But those problems deosn't show when I add "Base." inside to style apptheme.
What did I so far
Someone says it's about "com.android.support:appcompat-v7:28.0.0"
So use "com.android.support:appcompat-v7:28.0.0-alpha1" but it's didn't work.Also I tried with alpha3.
I change apptheme on style.xml I tried "NoActionBar","Dark.ActionBar" and so many others.But nothing change.
Clear cache but it's didn't work.
I add ".Base" inside to style.xml (apptheme).
MainActivity
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
</android.support.constraint.ConstraintLayout>
Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.test.parala"
minSdkVersion 17
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-alpha3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-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'
}
Gradle2
// Top-level build file where you can add configuration options common to all sub-projects/modules.
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
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.parala">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Style
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="koko" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:actionBarSize">40dp</item>
</style>
This may not the completely right answer.But it's pratic for any other case.Down your gradle v27.This way the toolbar appears on layout manager, and upgrade again to v28 just before publishing your project.

No record for key [permission#${applicationId}.permission.C2D_MESSAGE]

I am using Android Studio 2.2.2 and Gradle version is 2.14.1.My project run fine in one computer. When i try to open same project in another computer then it send me below error:
Error:Execution failed for task ':app:processReleaseManifest'.
> No record for key [permission#${applicationId}.permission.C2D_MESSAGE]
Information:Gradle tasks [clean, :app:generateReleaseSources, :app:prepareReleaseUnitTestDependencies, :app:mockableAndroidJar]
I have checked this and this or other questions but not solved my issue. If any one can help me then please.Thanks in advance.
This is my AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.newsongplay.app">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.vending.BILLING" />
<!-- GCM -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.newsongplay.app.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.newsongplay.app.permission.C2D_MESSAGE" />
<application
android:name="com.newsongplay.app.activity.WaraMusicApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:icon">
<activity
android:name="com.newsongplay.app.activity.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
//Other activity also here
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.google.android" />
</intent-filter>
</receiver>
<service
android:name=".gcm.PushNotificationService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>
</manifest>
This is my app level build.gradle file
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.newsongplay.app"
minSdkVersion 16
targetSdkVersion 23
versionCode 2
versionName "1.0.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.mimecraft:mimecraft:1.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.malmstein:fenster:0.0.2'
compile 'com.facebook.android:facebook-android-sdk:4.16.0'
compile 'com.google.android.gms:play-services-auth:9.0.1'
compile 'com.google.android.gms:play-services-plus:9.0.1'
compile 'com.google.android.gms:play-services-gcm:9.0.1'
compile 'org.apache.commons:commons-io:1.3.2'
}
apply plugin: 'com.google.gms.google-services'
I solved my problem by this question's answer which is provided by #shailesh.
I changed to this in my AndroidManifest.xml file
<!-- GCM -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
I don't know but it work for me.
I have met this issue due old dependency library reference project-level build.gradle.
In my case is was Firebase
classpath 'com.google.gms:google-services:3.0.0'
I have updated it to
classpath 'com.google.gms:google-services:3.1.0'
Also I have updated config file from Firebase console and problem has been solved.
Maybe it helps you...
Found the solution to this problem:
gradle assemble -info gave me the hint that the Manifests have different SDK Versions and cannot be merged.
I needed to edit my Manifests and build.gradle file and everything worked again.
To be clear you need to edit the uses-sdk in the AndroidManifest.xml
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="16" />
and the android section, particularly minSdkVersion and targetSdkVersion in the build.gradle file
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
}

Android studio not recognize the <uses-permission > entry in the AndroidManifest.xml

I created simple sms messaging app on android studio 1.5 (watch my eclipse app code on github), based on eclipse project which alredy works fine (watch my android studio app code on github)
When I run the android studio version , it's not recognize the permission , produce this error : Sending SMS message: uid 10166 does not have android.permission.SEND_SMS
I attach the android studio project manifest and gradle.build :
manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.findmee.myapplication5">
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
the gradle.build :
>apply plugin: 'com.android.application'
>android {
> compileSdkVersion 23
> buildToolsVersion "23.0.2"
>
> defaultConfig {
> applicationId "com.findmee.myapplication5"
> minSdkVersion 15
> targetSdkVersion 23
> versionCode 1
> versionName "1.0"
> }
> buildTypes {
> release {
> minifyEnabled false
> proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
> }
> }
>}
>
>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'
>}
>
Sorry about the ugly format of the grade code
Thanks in advance!!
I fount that , think it will be useful for other users who try do debug/deploy their apps on android 6.0 devices.
The matter is you have to manualy enaple every permission to every app in youre 'apps' section on the setting on youre device.
Good luck!

Resources