I'm updating an app, to add Android 8+ support, I was trying to get the app Notifications to work properly (using the now required Channels), but for some reason I can't use the new NotificationCompat.Builder constructor (Context, String).
I've already updated my buildToolsVersion (28.0.3 at the moment), as seen here, yet I'm still unable to use the new constructor.
//IDE won't let me use:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "channelId");
//While this works fine:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
Any ideas on why this could be happening? I already tried to find a solution, but most of them just tell you to update the buildToolsVersion.
Relevant build.gradle code:
android {
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 27
...
}
dependencies {
...
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
...
}
I found out what was going on, turns out that the build.gradle file had a configuration script that was overriding all my support dependencies versions to use the v25.3.0. After removing that script the correct lib was imported and the problem was solved.
//This script
...
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.3.0'
}
}
Related
I have checked that on 2 devices and 1 emu, I can't change the language of my app anymore using localization. even when I do that manually, even when I go back using git to commits where it was tested and working good. The implementation is good, it was working for months but it is not working for debug and release version. It just picked the main language which is English.
I can still change the language from android studio and preview this before running the app, but when I run the app on any device I can't change it anymore.
What I have tried?
running the app on multiple devices
go back to previous commits where it was tested (it was working good, but now not working anymore)
checking the implementation and trying to change that and give that hardcoded values
checking gradle (I am not good with gradle, I think here is the problem)
until now I didn't figure out where is the problem. Can u please tell me what all the reasons that could involved localization in android? I have been working for about a week but I give up, I have to ask now.
here is gradle code (I have undo the changes about lintOptions and still doesn't work)
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.company.app"
minSdk 21
targetSdk 32
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
}
buildToolsVersion '33.0.0'
buildFeatures {
viewBinding true
}
flavorDimensions 'default'
productFlavors {
free {
dimension 'default'
applicationIdSuffix 'free'
}
paid {
dimension 'default'
applicationIdSuffix 'paid'
}
}
sourceSets{
free{
res{
srcDir 'src/free/res'
}
java{
srcDir 'src/free/java'
}
}
paid{
res{
srcDir 'src/paid/res'
}
java{
srcDir 'src/paid/java'
}
}
}
useLibrary 'org.apache.http.legacy'
packagingOptions {
resources {
excludes += ['META-INF/DEPENDENCIES', 'META-INF/NOTICE', 'META-INF/LICENSE', 'META-INF/LICENSE.txt', 'META-INF/NOTICE.txt']
}
}
namespace 'com.company.app'
}
dependencies {
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
def room_version = "2.4.2"
def lifecycle_version = "2.6.0-alpha01"
//room
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// viewModelProvider
implementation "androidx.fragment:fragment-ktx:1.5.2"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
// Annotation processor
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// google sign in
implementation 'com.google.android.gms:play-services-auth:20.3.0'
// google drive
implementation 'com.google.api-client:google-api-client:2.0.0'
implementation 'com.google.auth:google-auth-library-oauth2-http:1.3.0'
implementation ('com.google.apis:google-api-services-drive:v3-rev20220815-2.0.0')
}
Java Code
Locale languageToSwitch = new Locale("nl");
Locale.setDefault(languageToSwitch);
Resources res = getBaseContext().getResources();
DisplayMetrics dm = Resources.getSystem().getDisplayMetrics();
Configuration config = res.getConfiguration();
config.locale = languageToSwitch;
res.updateConfiguration(config, dm);
recreate();
I tried to invalidate the caches but it didn't work, It is solved after removing the project and android Studio and then cloned it again from github.
If u know why that happens tell me please.
I am working on a app for school in android studio using java
I want to generate multiple apk for school with their school name and logo, (about 50+ schools)
Is there any way to save time generating one by one
in future need to update all
Read official guideline about productFlavors.
Creating product flavors is similar to creating build types: add them
to the productFlavors block in your build configuration and include
the settings you want. The product flavors support the same properties
as defaultConfig—this is because defaultConfig actually belongs to the
ProductFlavor class.
productFlavors {
elvispresley {
applicationId 'your_package_id'
versionCode 1
versionName '1.0'
}
whitneyhouston {
applicationId 'your_package_id_2'
versionCode 2
versionName '2.0.1'
}
projectOne {
applicationIdSuffix ".one"
}
projectTwo {
applicationIdSuffix ".two"
}
}
In my react native project I earlier added aws amplify for push notification. After that I wanted to do analytics, so I added firebase to it. After that, my android app build but stops as soon as it launches.
I get error as
java.lang.RuntimeException: Unable to instantiate service
com.amazonaws.amplify.pushnotification.RNPushNotificationMessagingService:
java.lang.ClassNotFoundException: Didn't find class
"com.amazonaws.amplify.pushnotification.RNPushNotificationMessagingService
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of:
Lcom/google/firebase/messaging/FirebaseMessagingService;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 10 more
Caused by: java.lang.ClassNotFoundException: com.google.firebase.messaging.FirebaseMessagingService
My app/build.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
packagingOptions {
pickFirst 'lib/x86_64/libjsc.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libjsc.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
defaultConfig {
applicationId "com.project”
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 2
versionName "1.1"
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [
appAuthRedirectScheme: 'com.project’
]
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':react-native-firebase')
implementation project(':react-native-gesture-handler')
implementation project(':react-native-reanimated')
implementation project(':#react-native-community_netinfo')
compile project(':react-native-charts-wrapper')
compile project(':rn-fetch-blob')
compile project(':react-native-wheel-picker')
compile project(':react-native-vector-icons')
compile project(':react-native-pdf')
compile project(':react-native-app-auth')
compile project(':#aws-amplify_pushnotification')
implementation (project(':react-native-device-info')){
exclude group: "com.google.android.gms"
exclude group: "com.android.support"
}
implementation project(':react-native-wheel-picker')
implementation project(':react-native-vector-icons')
implementation project(':amazon-cognito-identity-js')
implementation project(':#aws-amplify_pushnotification')
implementation project(':react-native-app-auth')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
// Firebase dependencies
implementation "com.google.android.gms:play-services-base:16.1.0"
implementation "com.google.firebase:firebase-core:16.0.9"
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
//com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
You have to either use compile or implementation, not both. Remove these lines.
compile project(':react-native-wheel-picker')
compile project(':#aws-amplify_pushnotification')
compile project(':react-native-vector-icons')
compile project(':react-native-app-auth')
When you set up AWS Amplify push notifications, you have to first set up a Firebase project that AWS Amplify will hook into.
You can Enable Google Analytics in the Firebase project setup process.
Then include the line implementation 'com.google.firebase:firebase-analytics:17.2.1' in android/app/build.gradle.
I've created a walkthrough for the Firebase setup process for AWS Amplify, containing images for the various steps.
Yesterday my app was building correctly and today without changing anything I'm not able to build anymore, I'm getting this error:
Android dependency 'com.google.android.gms:play-services-stats' has >different version for the compile (16.0.1) and runtime (17.0.0) >classpath. You should manually set the same version via >DependencyResolution
I tried to bypass this with "com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true" and clean the project many times, but the error is still here.
My app/build.gradle file :
apply plugin: "com.android.application"
apply plugin: "com.android.application"
apply plugin: "io.fabric"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.yapero"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled true
versionCode 743
versionName "1.74"
ndk {
abiFilters "armeabi-v7a", "x86"
}
versionNameSuffix '3'
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
packagingOptions {
exclude 'META-INF/main.kotlin_module'
exclude 'META-INF/-no-jdk.kotlin_module'
}
dexOptions {
javaMaxHeapSize "4g"
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':#segment_analytics-react-native')
implementation project(':react-native-webview')
implementation project(':react-native-version-check')
implementation project(':react-native-firebase')
implementation(project(':react-native-firebase')) {
transitive = false
}
implementation('com.crashlytics.sdk.android:crashlytics:2.9.5#aar') {transitive = true}
//implementation project(':react-native-version-check')
implementation project(':react-native-maps')
implementation project(':react-native-intercom')
implementation 'io.intercom.android:intercom-sdk-base:5.+'
implementation 'io.intercom.android:intercom-sdk-fcm:5.+'
implementation project(':react-native-fbsdk')
implementation project(':react-native-device-info')
implementation project(':react-native-appsflyer')
implementation project(':react-native-text-input-reset')
implementation project(':react-native-linear-gradient')
implementation project(':react-native-fast-image')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "com.google.android.gms:play-services-base:16.1.0"
implementation "com.google.firebase:firebase-core:16.0.8"
implementation "com.google.firebase:firebase-auth:16.2.1"
implementation "com.google.firebase:firebase-firestore:17.1.5"
implementation "com.google.firebase:firebase-messaging:17.5.0"
implementation 'me.leolin:ShortcutBadger:1.1.21#aar'
implementation 'com.android.support:multidex:1.0.0'
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
My build.gradle:
buildscript {
ext {
buildToolsVersion = "28.0.2"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'io.fabric.tools:gradle:1.25.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.7'
distributionUrl = distributionUrl.replace("bin", "all")
}
Does someone know how to correct or bypass this version check ? Ask me if you need more informations.
This comment on github provides the answer to your question (and mine):
A dependency (react-native-device-info in this case) was using the latest version of one of its dependencies instead of a fixed/pinned version. When a new version of google services was released yesterday, it caused the build to pull in the new version for device-info, thereby causing the conflict with other dependencies that correctly pin the version they need.
The solution is to do what is explained in the linked post in your android/app/build.gradle:
implementation(project(":react-native-device-info"), {
exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-gcm:16.0.0"
and possibly replace react-native-device-info with any other dependency that may have the same problem (they would include a line like implementation "com.google.android.gms:play-services-gcm:+" which depends on whatever is the latest version of google gcm).
Add in the file: android/app/build.gradle
android {
...
dependencies {
implementation 'com.google.android.gms:play-services-maps:17.0.0'
}
I'm trying to include a c file, ImageProc into my java file to use it's functions.
I got the code from a MjpegInputStream file (where everything is supposed to work, but of course its never that easy)
Here is the code that crashes (somehow the catch isn't catching it)
static {
try {
System.loadLibrary("ImageProc");
}
catch (Exception e){
e.getMessage();
}
}
The makefile is:
include $(CLEAR_VARS)
LOCAL_MODULE := ImageProc
LOCAL_SRC_FILES := ImageProc.c
LOCAL_LDLIBS := -llog -ljnigraphics
LOCAL_SHARED_LIBRARIES := prebuilt-libjpeg
LOCAL_C_INCLUDES := external/include jni/external/include
So to my understanding I should just be able to use ImageProc.
I know it went through and compiled the c file because at first it couldn't find the h file references (fixed now).
One other thing i'm not sure about is that I call the function pixeltobmp which in the c file is defined as Java_com_camera_simplemjpeg_MjpegInputStream_pixeltobmp which strikes me as odd. I tried changing the name of the method to include the package i'm using rather than the one I copied it from, but that didn't fix anything.
Any help is appreciated.
Additional info: I'm using gradle build 2.10
1. Compile your library
2. Check if you have the .so compiled library(this is important!)
3. In your gradle file add this:
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
sourceSets.main {
jni.srcDirs = []
File configFile = file('pathToYourLibsFolder')
jniLibs.srcDir configFile.absolutePath
}
Then it should work.
In build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
...
}
buildTypes {
...
}
ndk {
moduleName "ImageProc"
// stl "stlport_static"
// ldLibs "log"
}
}
}
As an alternative option, the code that you're using can be easily modified to remove the dependency on OpenCV (or it can now 2 years after you asked the question).
MjpegInputStream.java has two relevant methods, readMjpegFrame() and readMjpegFrame(Bitmap bmp).
Only the later relies on OpenCV and therefore the native library dependency. If you modify the code to remove this method, and then remove:
static {
System.loadLibrary("ImageProc");
}
public native int pixeltobmp(byte[] jp, int l, Bitmap bmp);
public native void freeCameraMemory();
You will no longer have this problem and can still use readMjpegFrame() to get the content you want.
Whether this is less performant, I'm not certain, but it's working fine in my use case.