Android Gradle referencing styles from dependent module - resources

so I have an Android project in Android Studio (0.6.1). There are 2 Modules A and B. A is my main-module and it depends on B which includes various resources (drawables, strings, styles) and therefore functions as something like a library (although it is no library-project). I added B as git-subtree, included it in my settings.gradle and building works fine.
Now there is a problem: I want to reference resources from B in A. For drawables I already found out here that I can just create dummy resources in A that will be overridden by B. But unfortunately that doesn't work for styles, that are defined in B. The dummies I create in styles.xml in A are not overwritten.
My aim is to define multiple styles in B like:
<style name="ButtonStyle1" parent="android:Widget.Button">
<item name="android:layout_width">wrap_content</item>
<item name="android:minWidth">200dp</item>
<item name="android:background">#drawable/buttonorange</item>
<item name="android:textColor">#android:color/black</item>
</style>
<style name="ButtonStyle2" parent="android:Widget.Button">
<item name="android:layout_width">wrap_content</item>
<item name="android:minWidth">200dp</item>
<item name="android:background">#drawable/buttonorange</item>
<item name="android:textColor">#android:color/black</item>
</style>
And then back in A I want to have the opportunity to choose wether to apply ButtonStyle1 or ButtonStyle like:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:buttonStyle">#style/ButtonStyle1</item>
</style>
or
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:buttonStyle">#style/ButtonStyle2</item>
</style>
But when I do this, I always get
Error:(5, 42) No resource found that matches the given name (at 'android:buttonStyle' with value '#style/ButtonStyle1').
All in all I guess that my gradle configuration itself is correct because overriding drawables works fine already. So what am I doing wrong - how can I reference styles defined in B in A?
settings.gradle
include ':app', ':uiframework:uiframework'
build.gradle from A
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
applicationId 'com.example.uiframeworkexample'
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':uiframework:uiframework')
}

Make sure you apply correct plugin for your B(library) project at build.gradle file
apply plugin: 'com.android.library'

Related

keep getting an error when I open android studio

I recently installed Android Studio and when ever I start a new Project no matter what I keep getting this error :
Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/4.2.0-beta03/gradle-4.2.0-beta03.pom'. Received status code 403 from server: Forbidden
Disable Gradle 'offline mode' and sync project.
and offline mode doesn't work either . I really ran out of ideas . if anyone can help me please do. thanks.
this is my build gradle :
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapplication"
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.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
and this is build.gradle :
// 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:4.2.0-beta03"
// 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
}
and when I'm clicking on Offline mode this error appears :
A problem occurred configuring root project 'My Application'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:4.2.0-beta03.
Required by:
project :
> No cached version of com.android.tools.build:gradle:4.2.0-beta03 available for offline mode.
> No cached version of com.android.tools.build:gradle:4.2.0-beta03 available for offline mode.
Possible solution:
- Disable offline mode and rerun the build
The always working and best solution is to delete the full application with the sdk's if you have any projects take a backup of them and reinstall android studio. That's the most easiest way.
Try to disable gradle offline mode. You can find how to here: How to disable gradle 'offline mode' in android studio?. Then wait for gradle files to sync after restart.
Jcenter is no longer available.
You must replace all jcenter()s in you build.gradle with mavenCentral().
Also check your Internet connection(VPN) and proxies because it seems you have problems with your connection.

Why isn't .aab file added -free-release or -pro-release.apk suffix automatically when I use the same build.gradle in Android Studio?

I use the following build.gradle to generate .apk files, the result will be MagnifyingGlass-V1.01-free-release.apk for free edition and MagnifyingGlass-V1.01-pro-release.apk for pro edition. -free-release or -pro-release is added to filename as suffix automatically by Android Studio 3.4.2.
I try to use the same build.gradle to generate .aab files, I find the result is MagnifyingGlass-V1.01 for free and MagnifyingGlass-V1.01 for pro, there are same, why? -free-release or -pro-release isn't added to filename as suffix automatically by Android Studio 3.4.2.
Added content:
I generated different edition .apk and .aab using Android Studio just like Image 1.
build.gradle
android {
compileSdkVersion 28
flavorDimensions "default"
defaultConfig {
applicationId "info.dodata.magnifyingglass"
minSdkVersion 21
targetSdkVersion 28
versionCode 2
versionName "1.02"
archivesBaseName = "MagnifyingGlass-V" + versionName
}
productFlavors {
free {
applicationId "info.dodata.magnifyingglass"
}
pro {
applicationId "info.dodata.magnifyingglass.pro"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "boolean", "IsDebugMode", "false"
}
debug {
buildConfigField "boolean", "IsDebugMode", "true"
}
}
}
Image 1
This is because the name of the bundle is being rigidly applied (there might be a relevant ticket available on the issue-tracker).
Once left a workaround here: How to change the generated filename for App Bundles with Gradle?
This approach can also be used to finalize these flavors, based upon their final task's name. Another optimization would be, to use the Apache Ant integration on the generated bundle. For some reason (unknown to me), Gradle does not support move (rename) operations out-of-the-box.
This configuration appears pretty useless (and there might be other configurations missing):
buildConfigField "boolean", "IsDebugMode", "true"
because in Java that is known as BuildConfig.DEBUG; better replace that with configuration applicationIdSuffix ".debug" - and also add the corresponding applicationIdSuffix ".release" (which rather sounds alike the intended outcome); for example:
buildTypes {
release {
applicationIdSuffix ".release"
...
}
debug {
applicationIdSuffix ".debug"
...
}
}
This is now available in gradle version 3.5.2 where the product flavor suffix is applied automatically.

Is Multidex support for Android Studio?

When I tried using Picaso and OKHttp together in to app/build.gradle this issue started. Please help me to resolve this issue. Thanks you in advance.
Multidex support for **Android 5.0 and higher**
Step 1 : add MultidexEnabled true in app/build.gradle
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
// Enabling multidex support.
multiDexEnabled true
}
**Step 2 :**
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
**Step 3:** in your manifest add the MultiDexApplication class from the multidex support library to the application element.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
For More details about this please refer Google Developer site:
[Click Here][1]
I hope this help.
[1]: http://developer.android.com/intl/es/tools/building/multidex.html

How to add service in a library in android?

I have a project with service which scans the Bluetooth devices in the range and when i get the signal it will broadcast the device details.
I want to create a library of that service so anyone can import my library and use it.
How can i do this ?
I got the solution
First make changes in the build.gradle
do the changes as show bellow
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 22
}
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:22.2.1'
}
task deleteOldJar(type: Delete){
delete 'release/customlib.jar'
}
task exportJar(type: Copy) {
from('/build/intermediates/bundles/release/')
into('/release/')
include('classes.jar')
//rename the file name as u want
rename('classes.jar','myLibrary.jar')
}
exportJar.dependsOn(deleteOldJar,build)
sync the project then click on the right menu bar gradle option u will
-MyLibrary
-:app/Task/Other/exportJar
here you will see exportJar double click on it will create a jar file after the build successful u can check the jar file at location /app/release/MyLibrary.jar
Your question is not very clear. For building a library, you must have source code for it. Once you have the library, a system service would attach that library with itself either at boot time or event-based. You need to be clear what you need to do. You can not add a service in a library rather it's the opposite.

Trying to make an Android Studio Application with Adobe Creative SDK Image Editing, cannot get libraries compiled in gradle

I've been trying to properly import this library to begin writing an image editing component for my application. I currently have the downloaded 'creativesdk-repo' folder in the root directory, and have followed instructions according to this tutorial:
https://creativesdk.adobe.com/docs/android/#/articles/gettingstarted/index.html.
And this tutorial as well:
https://creativesdk.adobe.com/docs/android/#/articles/imageediting/index.html
There are no problems building when I simply use the basic authorization library, but my application needs photo editing capability. My foremost problem (among many) lies within the build.gradle file of the application (not the encompassing project build.gradle file).
Here is the code in my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
applicationId "com.example"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.adobe.creativesdk.foundation:auth:0.3.94'
compile 'com.adobe.creativesdk.image:4.0.0'
}
The very last line causes an error message to appear:
Error:Failed to resolve: com.adobe.creativesdk.image:4.0.0:
Open File
I believe these messages mean that the image editing portion of the Adobe Creative SDK libraries are not being recognized. I have even tested this with example projects from Adobe and it runs into the same problem. What can I do to fix this and start writing this portion of my application?
You need download creative-sdk repo from download links into your project folder. In the project gradle define creative-sdk repo url like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
jcenter()
maven{
url "${project.rootDir}/creativesdk-repo" //ADD THE CORRECT LOCATION OF THE CREATIVESDK LIBRARY FILES
}
}
}
In your app build.gradle define this:
compile 'com.adobe.creativesdk.foundation:auth:0.3.94'
compile 'com.adobe.creativesdk:image:4.0.0'
You should extend your Application class and implement this, something like this:
public class ExampleApplication extends MultiDexApplication implements IAdobeAuthClientCredentials , IAviaryClientCredentials {
private static final String CREATIVE_SDK_SAMPLE_CLIENT_ID = "62bbd145c3f54ee39151823358c83e28";
private static final String CREATIVE_SDK_SAMPLE_CLIENT_SECRET = "2522a432-dfc8-40c4-94fe-646e10223562";
#Override
public void onCreate() {
super.onCreate();
AdobeCSDKFoundation.initializeCSDKFoundation(getApplicationContext());
}
#Override
public String getClientID() {
return CREATIVE_SDK_SAMPLE_CLIENT_ID;
}
#Override
public String getClientSecret() {
return CREATIVE_SDK_SAMPLE_CLIENT_SECRET;
}
#Override
public String getBillingKey() {
return "";
}
}
In your AndroidManifest.xml inside Application tag put this:
<provider
android:name="com.aviary.android.feather.sdk.internal.cds.AviaryCdsProvider"
android:authorities="com.package.AviaryCdsProvider"
android:exported="false"
android:process=":aviary_cds" />
With this configuration you can call Aviary Sdk Activity with this:
Intent newIntent = new AviaryIntent.Builder(this);
//config values
startActivity(newIntent);
I configure SDK like this, and its working. Sorry for the delay.
UPDATE 10/10/2016:
Thanks to Ash Ryan:
Trying to make an Android Studio Application with Adobe Creative SDK Image Editing, cannot get libraries compiled in gradle
Use this:
//noinspection SpellCheckingInspection
repositories {
// ...
// For Adobe Creative SDK
maven { url 'https://repo.adobe.com/nexus/content/repositories/releases/' }
}
Source: https://creativesdk.adobe.com/docs/android/#/articles/gettingstarted/index.html
Please make sure under global project repo. If not gradle not able to find the path.
allprojects {
repositories {
compile 'com.adobe.creativesdk.foundation:auth:0.3.94'
compile 'com.adobe.creativesdk:image:4.0.0'
}
I think your error is here. Change:
complie 'com.adobe.creativesdk.image:4.0.0'
for this:
compile 'com.adobe.creativesdk.image:4.0.0'
It`s a simple sintax error.
UPDATE 10/10/2016:
Thanks to Ash Ryan:
Trying to make an Android Studio Application with Adobe Creative SDK Image Editing, cannot get libraries compiled in gradle
just use latest lib dependency in Module:app build.gradle file and update your android sdk and android studio
compile 'com.adobe.creativesdk:image:4.6.3'

Resources