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"
}
}
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 a newbie with Android Studio. I am trying to use this project library : https://github.com/2dxgujun/AndroidTagGroup in my project.
So what I did is to import it as a module in my project ; with the name "androidtaggroup"
Now, I have got the following error at compilation:
"Could not get unknown property 'VERSION_NAME' for project ':androidtaggroup' of type org.gradle.api.Project."
Here is where the problem occurs in the Gradle file:
defaultConfig {
applicationId 'me.gujun.android.taggroup.demo'
minSdkVersion 8
targetSdkVersion 21
versionName project.VERSION_NAME // ERROR HERE !!!!
versionCode Integer.parseInt(project.VERSION_CODE)
}
Anybody can tell me how to fix this problem ?
Thanks !!!
The fix is to define your version name there or use a custom made variable. project.VERSION_NAME does not exists by default, therefore you can't use it. That is basically what the error message is telling you.
defaultConfig {
applicationId 'me.gujun.android.taggroup.demo'
minSdkVersion 8
targetSdkVersion 21
versionName "1.2.3"
versionCode Integer.parseInt(project.VERSION_CODE)
}
or alternative:
// somewhere above
def VERSION_NAME = "1.2.3"
// and the usage:
defaultConfig {
applicationId 'me.gujun.android.taggroup.demo'
minSdkVersion 8
targetSdkVersion 21
versionName VERSION_NAME
versionCode Integer.parseInt(project.VERSION_CODE)
}
And after you have changed that you will probably run into the same issue for using project.VERSION_CODE:
versionCode Integer.parseInt(project.VERSION_CODE)
Fix is the same: provide a valid self defined variable or constant
buildscript {
ext.kotlin_version = '1.3.31'
ext.room_version = '2.1.0-alpha01' // Add this line in your build gradle
repositories {
google()
jcenter()
}
I had a similar problem. 'VERSION_NAME' was not defined in the ext{} from build.gradle(Project: 'PROJECT_NAME')
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.
My Gradle dependencies includes:
compile'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.google.android.gms:play-services-analytics:8.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0
I am getting BUILD FAILED with error:
Error:Execution failed for task ':app:processDebugResources.
Error: more than one library with package name 'com.google.android.gms'
You can temporarily disable this error with android.enforceUniquePackageName=false
However, this is temporary and will be enforced in 1.0
How can I solve this problem?
Use gradle androidDependencies to learn where the duplicate Google Play Services is coming from. Then use exclude to filter the duplicates out in your Gradle dependencies, e.g.
compile('something.that.includes.google.play.services:1.2.3') {
exclude group: 'com.google.android.gms'
}
I had the same problem and I solved by adding this line android.enforceUniquePackageName = false in build.gradle(app) like this:
buildTypes {
release {
...
... ...
}
}
android.enforceUniquePackageName = false
The easiest way is to replace these dependencies by the whole package :
compile 'com.google.android.gms:play-services:8.1.0'
Then you could probably compile it.
OR add android.enforceUniquePackageName = false in your build.gradle.
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion 9
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
android.packageBuildConfig = false
android.enforceUniquePackageName = false
}
I'm using Android Studio 1.1.0. When I try to sync my Gradle file, I get the following error:
Gradle DSL method not found:storeFile()
Here is my gradle configuration:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "skripsi.ubm.studenttracking"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
signingConfigs {
release {
storeFile (project.property("Students_tracking_keystore.jks") + ".keystore")
storePassword "####"
keyAlias "####"
keyPassword "#####"
}
}
}
Can anyone help?
A couple of things to note:
The storeFile DSL method has the following signature:
public DefaultSigningConfig setStoreFile(File storeFile)
i.e. it expects a File to be passed in. You probably need to place a File constructor in your code to ensure you are actually creating a File object. Because you're currently not passing in a file, Gradle is complaining that it can't find a method with the appropriate signature.
Secondly, you are currently appending two suffices to the filename: .jks and .keystore. You should only include one of these based on the suffix of the file you are referencing (it's probably .jks, but you should check to be sure).
In short, one of the following replacement lines will probably work for you:
storeFile file(project.property("Students_tracking_keystore") + ".keystore")
or
storeFile file(project.property("Students_tracking_keystore") + ".jks")
or
storeFile file(project.property("Students_tracking_keystore.keystore"))
or
storeFile file(project.property("Students_tracking_keystore.jks"))