I'm having an issue with an aar in a jetpack compose project.
I've created a library which contains all the string resources I'm using in multiple projects. In my old java/kotlin projects there is no issue and I can implement the library and reach the strings. But when I do this in my new jetpack compose project it loads the aar but when in code I do R.string. I don't see the specific strings.
Also when I add some kotlin classes with functions in the library, these functions can be accessed. This way I'm 100% sure the library is loaded.
Is there a way to solve this?
The android manifest for the library looks like:
<manifest package="com.test.library"/>
The build.gradle:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdk 31
defaultConfig {
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
android.libraryVariants.all { variant ->
def debug = ""
if (variant.name == "debug") {
debug = "-debug"
}
variant.outputs.all {
outputFileName = "TestLibrary" + debug + ".aar"
}
}
}
}
}
dependencies {
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
In my jetpack compose project I implement it with the following call:
implementation files('libs/TestLibrary.aar')
How can I solve this? Is there somebody with the same issue (and a solution)?
Kind regards,
Jeroen
I also have been struggling with this for a while and I believe I found what causes this issue.
Your jetpack compose project should have a new entry in its gradle.properties file. The entry should look like this:
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
If you change this value to false your project should be able to find the string resources declared in your library. As the description shows.
So your new entry will look like this:
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=false
Hope this helps!
Related
In our Kotlin Mobile Multiplatform project for iOS and Android, we're trying to access TrustWalletCore cocoapod from Kotlin.
// build.gradle.kts (:shared)
cocoapods {
version = "1.0"
podfile = project.file("../iosApp/Podfile")
pod("WalletCore")
}
And the Podfile is
target 'iosApp' do
pod 'TrustWalletCore'
end
This successfully enables import cocoapods.WalletCore.* in shared/iosMain - without the above cocoapods {...} the import is unavailable.
However, only a Crypto class is available from this package (and CryptoMeta which doesn't look too different).
By the looks of it, it's generated from the Pod/library by commonizer in 0_WalletCore.knm (about 15 expect functions in total - a couple here for illustration):
#kotlin.commonizer.ObjCCallable public open external expect fun base58Encode(data: platform.Foundation.NSData): kotlin.String { /* compiled code */ }
#kotlin.commonizer.ObjCCallable public open external expect fun generateMnemonicFromSeed(seed: platform.Foundation.NSData): kotlin.String { /* compiled code */ }
It has mnemonic-related functionality, as well as signHash/verifySignature but not much else.
I was hoping to see - available to import in Kotlin - classes like HDWallet, EthereumSigningInput etc.
I can use these library classes in Swift, via pod TrustWalletCore in Xcode (import WalletCore).
WHY can I not get a similar/full set of classes via native.cocoapods plugin?
Try to declare dependency with moduleName parameter:
kotlin {
cocoapods {
...
pod(name = "TrustWalletCore", version = "3.1.0", moduleName = "WalletCore")
}
}
I am trying to use shared code in my iOS project from cocoapods that i created with cocoapods gradle plugin.
Podspec is created without problems.
My shared build.gradle:
plugins {
id("org.jetbrains.kotlin.multiplatform")
id("com.android.library")
id ("org.jetbrains.kotlin.native.cocoapods")
}
android {
compileSdkVersion 29
buildToolsVersion '30.0.0'
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
version = "1.0"
kotlin {
ios()
android()
cocoapods {
// Configure fields required by CocoaPods.
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
// The name of the produced framework can be changed.
// The name of the Gradle project is used here by default.
frameworkName = "toshlShared"
}
sourceSets {
commonMain.dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-common'
}
androidMain.dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
}
iosMain.dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
}
}
}
When i run pod install all looks good, but when i run ios app i see this error:
EDIT: Added my project folder structure with my single .kt file (it is accessible from android code)
As far as I can see, the problem here is caused by the project structure. In the Gradle script, there are three targets declared: an Android one, and iosX64+iosArm64 shortcut(see details here) providing the other two. For this layout, there would be two compilations per iOS target(iosX64Main, iosX64Test, iosArm64Main, iosArm64Test) and
a compilation per Android build variant, for Android targets;
according to the documentation.In this particular case, only source file SharedUtils.kt is being located in a directory located on an Android main compilation's source set. This means it does not get into any iOS compilation. To make this source file shared, it should be relocated to the common code. There are two default source sets for common code in Kotlin Multiplatform: commonMain and commonTest. Therefore, source code should be placed under src/<sourceSetName>/kotlin directory(commonMain for this case).
I can't get my C code using native OpenCV to work in Android Studio. OpenCV through the Java wrappers work, but I have been banging my head against this for the last couple of days trying to get it to work with the native libraries. (I have some C code that depends on OpenCV that I need to use in my project)
To pin down the problem I'm trying to get the tutorial-2-mixedprocessing OpenCV sample project to build in AS.
OpenCV is in a separate module in the project, with the shared libraries (.so, .a files) in jniLibs, and the headers are in jni. The application module has a dependency on it. See the image below for the sample code and result when building.
Apparently the headers are not found?
I have tried adding the -I flag to CFlags in android.ndk in the gradle file with no success:
CFlags.add("-I${file("path/to/opencv-android-sdk/native/jni/include/")}".toString())
I have also tried placing the headers in the app module jni folder, as well as using different versions of Android Studio and Gradle.
I keep finding outdated solutions and conflicting information online, it seems like the build system in Android Studio is still changing a lot between versions. I'm also new to both Android development and NDK, so apologies if this is a stupid question. All I really need is a working sample that I can adapt to my project.
What am I missing?
Project structure:
Project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.7.2'
}
}
allprojects {
repositories {
jcenter()
}
}
OpenCV library module gradle:
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig {
minSdkVersion.apiLevel = 21
targetSdkVersion.apiLevel = 23
}
buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
}
}
Application module gradle:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig {
applicationId = "org.opencv.samples.tutorial2"
minSdkVersion.apiLevel = 21
targetSdkVersion.apiLevel = 23
}
ndk {
moduleName = "mixed_sample"
//CFlags.add("-I${file("path/to/opencv-android-sdk/native/jni/include/")}".toString())
}
buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
}
}
dependencies {
compile project(':openCVLibrary2411')
}
I have extended project in eclipse scout neon, and I would like to know how to enable texts it this project.
I copy Texts.nls file and create texts folder with Texts.properties inside.
Auto create texts from code doesn't work and give me an error :
The NLS Project is read-only. heck that you have a valid NLS Project in your workspace.
If I add text manually in texts.properties file, it doesn't read from it.
How to fix this?
Have you configured your Texts.nls file correctly? Here an example:
###############################################
# This file is maintained by the NLS editor. #
# To ensure a properly working NLS support #
# keep this file untouched. #
###############################################
Nls-Class=org.eclipse.scout.contacts.shared.TextProviderService
The corresponding TextProviderService java class:
package org.eclipse.scout.contacts.shared;
import org.eclipse.scout.rt.platform.Order;
import org.eclipse.scout.rt.shared.services.common.text.AbstractDynamicNlsTextProviderService;
#Order(2000)
public class TextProviderService extends AbstractDynamicNlsTextProviderService {
#Override
protected String getDynamicNlsBaseName() {
return "org.eclipse.scout.contacts.shared.texts.Texts";
}
}
This is the way how the Scout SDK lookup for your properties files.
I am trying to exclude a list of files or directories when building a web application with dart's pub build.
Using this, as suggested by the documentation:
transformers:
- simple_transformer:
$exclude: "**/CVS"
does not work:
Error on line 10, column 3 of pubspec.yaml: "simple_transformer" is not a dependency.
- simple_transformer:
Is there a way to do it (using SDK 1.10.0) ?
Sadly there is currently no support to mark files as ignored by pub build as Günter already mentioned. The .gitignore feature was removed as it was undocumented and caused more trouble than it solved.
But you can execlude files from the build output. This means that the files are still processed (and still take time to process =/ ) but aren't present in the output directiory. This is useful for generating a deployable copy of your application in one go.
In our application we use a simple ConsumeTransformer to mark assets as consumed so that they are not written to the output folder:
library consume_transformer;
import 'package:barback/barback.dart';
class ConsumeTransformer extends Transformer implements LazyTransformer {
final List<RegExp> patterns = <RegExp>[];
ConsumeTransformer.asPlugin(BarbackSettings settings) {
if (settings.configuration['patterns'] != null) {
for (var pattern in settings.configuration['patterns']) {
patterns.add(new RegExp(pattern));
}
}
}
bool isPrimary(AssetId inputId) =>
patterns.any((p) => p.hasMatch(inputId.path));
void declareOutputs(DeclaringTransform transform) {}
void apply(Transform transform) => transform.consumePrimary();
}
The consumer requires a list of regex patterns as an argument an consumes the matched files. You need to add the transformer to you pubspec.yaml file as the last transformer:
transformers:
- ... # Your other transformers
- packagename/consume_transformer:
patterns: ["\\.psd$"]
The example configuration ignores all files that have the psd extension, but you can add pattern as you need them.
I created a pub package that contains the transformer, take a look here.
simple_transformer is the name of the transformer you want to inform to exclude the files. If you want to apply this to dart2js you need to use the name $dart2js instead of simple_transformer.
For more details about configuring $dart2js see https://www.dartlang.org/tools/pub/dart2js-transformer.html