Raw resources aren't resolvable in android tests - android

R.raw.... resources that are located in src/androidTest/res/raw can't be resolved in android tests after updating Android build tools to 4.7.3. Resources were resolvable before updating build tools.
com.santaev.app.test.R isn't resolved.
Build output:
Unresolved reference: test

Android build tools 4.7.3 introduces namespace and testNamespace settings that allows to set package or generated file like R. Default values is same to package. com.example.myapp.R and com.example.myapp.test.R for tests).
See https://developer.android.com/studio/build/configure-app-module#change-namespace-for-testing.
Looks like that after updating build tools property testApplicationId isn't more supported that leads manifest package to be used as namespace.
Removing package from manifest of android test sources and removing testApplicationId:
defaultConfig {
// ...
testApplicationId 'com.example.myapp.test.R'
}
helped me.

Related

Android Navigation And Gradle 7.3.3 namespace Kapt Plugin Generated Directions Fail To Resolve Resources

since the new Android Studio Version "Chipmunk" the Gradle update helper suggests that you remove the package keyword from the AndroidManifest.xml and instead use a object namespace in the android block inside the app-level build.gradle.
However, using the recent version 2.4.2 and also with the version 2.5.0-rc01 of the standard navigation library, the Directions generated by the kapt plugin no longer import the correct resource path when a different applicationId is set for a build flavor.
For example if my default package name is my.package.com and I have a flavor called dev which is declared with a applicationId "my.package.com.dev" and the namespace is set to my.package.com, the generated directions all throw build errors: Unresolved reference: R.
Has anyone else stumbled over this issue and is there anything we can do to fix this?
I had to remove the namespace and put back in the package parameter in my AndroidManifest to resolve this issue, but that doesn't seem to be right.
I've just noted that this is a reported issue here. So adding back package name in manifest resolved the issue for the time being for my self.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.myapp.gcapp"
>

How can I specify custom NDK path in Android studio 4.1.3, gradle 6.8.3?

I am upgrading Android studio and Android gradle plugin to 4.1.3 and gradle to 6.8.3. I am using some protection for my code, which has its own special NDK 16b, which works with it without problems.
But that means, that I need to put this "security NDK 16b" to specific location and then tell the path to Android studio.
I have ndk.dir=myPath\android-ndk-r16b in my local.properties file. With the upgrade I can still build successfully, but there is new warning:
WARNING: NDK was located by using ndk.dir property. This method is deprecated and will be removed in a future release. Please use android.ndkVersion or android.ndkPath in build.gradle to specify the NDK to use. https://developer.android.com/r/studio-ui/ndk-dir
So I tried to use android.ndkVersion or android.ndkPath to point to ndk like this according to android docs (in my app build.gradle):
android {
ndkPath 'myPath/android-ndk-r16b' // Point to your own NDK
ndkVersion '16.1.4479499'
/// other stuff
}
but then it shows this error:
NDK at "pathToSDK\sdk\ndk-bundle" did not have a source.properties file
It searches for ndk in default Android studio path, so it seems, it does not use ndkPath property at all...
Should I use the ndkPath property in a different way? Does it work for someone?

R class not found after configuring applicationId by product flavors

I have two flavors in my app and I want a different applicationId for each one. This is what I have:
defaultConfig {
applicationId "com.mycompany.app"
//more stuff
}
...
productFlavors {
firstflavor {
applicationIdSuffix '.first'
//more stuff
}
secondflavor {
applicationIdSuffix '.second'
//more stuff
}
}
In AndroidManifest.xml, I have package="com.mycompany.app", and all the code is under that package.
When I assemble it with, say, flavor firstflavor, I get this error:
Error:The generated com.mycompany.app.first.R class cannot be
found
Shouldn't R.class be generated under com.company.app instead of com.company.app.first?
How is it package related to application id?
If I remove the application id flavor configuration (applicationIdSuffix), everything works properly.
EDIT
I have read this here:
If the BuildConfig.java and R.java files was set to the applicationId
rather than the package name, then the code which referenced these
would need to have different imports for different build variants – in
other words you would need to have separate source sets (with huge
amounts of duplication) for your different build flavors in order to
access these. This would have some quite profound implications for the
maintainability of our code.
However, error says that com.mycompany.app.first.R cannot be found. But, com.mycompany.app.first is the application id, not the package name! Why is that?
I'm using Android Annotations 3.3.2
I found the solution here. As I said, I'm using Android Annotations, so I needed to configure package name in apt plugin:
apt {
arguments {
//more things
resourcePackageName "com.mycompany.app" //add this line
}
}
and everything is working fine.
Use the file menu and do an invalidate caches and restart.
Use the invalidate and restart option there.
It'll rebuild the indexes and solve your issue. If that doesn't work, also do a clean build from the build menu and there'll been a gradle sync button on your toolbar, use that. Mostly the invalidate and restart should solve your issue of you don't have any other errors

Is there any way to specify gradle version when cordova creates android project?

I am using latest Cordova 5.4.0 and when I perform 'cordova platform add android' cordova creates gradle.build for gradle 2.1.1. I need to implement some JNI C++ code for android plugin, but this version doesn't support NDK well and I can't add NDK related section to the build file to introduce NDK support and set module name. Adding such section causes build errors (Gradle sync failed: Gradle DSL method not found: 'ndk()')
According to this manual http://ph0b.com/new-android-studio-ndk-support/ I am trying to add following section
android.ndk {
moduleName = "mymodule"
}
So, is there any way to force cordova to generate gradle.build for fresh gradle version like 2.8 or 2.9 ? Just changing gradle version in the build file from 2.2.1 to 2.8 doesnt work because there is new 'model' root namespace and probably other changes required.
Probably it is impossible at the moment. The best way to integrate cpp code to cordova android project is create separate JNI project, build libs for all possible platforms using ndk-build and integrate libs to your plugin in plugin.xml this way
Btw, it makes impossible debugging C++ code from Cordova project using Android Studio.
I also ran into this problem, this question helped but had to change a few things.
Here are the steps that fixed it for me.
Create gradle.properties (if it doesn't already exist) in the root folder of your app (where AndroidManifest.xml is)
Add the following line to it:
android.useDeprecatedNdk=true
In your build.gradle file, add "ndk" block under the android { defaultConfig { ... } }
android {
...
defaultConfig {
...
ndk {
moduleName "native"
}
}
}
You may have to change your gradleVersion if Android Studio prompts you to.
Rebuild your project and it should compile.

OpenCV Library error with AndroidStudio

I'm having issues with current Android project I'm working on, It has OpenCV Library imported as Module and set as dependency. After updating Android Studio from 0.8.14 to 1.0, and trying to sync Gradle I'm getting following error:
Error:Library projects cannot set applicationId. applicationId is set
to 'org.opencv' in default config.
I'd like to post my project structure and grade file, but I can't upload images yet.
Try commenting applicationID out of your library module's build.gradle file. Like this:
defaultConfig {
// applicationId "com.library.package"
minSdkVersion 14
targetSdkVersion 21
}
I'm still new at Android Studio, and am by no means an expert, but I got the same error after upgrading and this seems to fix it.
I tried to use comment, but instead to fix it, it generate new error (SOLVED).
With "applicationId 'lecho.lib.hellocharts'" enabled:
Library projects cannot set applicationId. applicationId is set to 'lecho.lib.hellocharts' in default config
With "applicationId 'lecho.lib.hellocharts'" disabled (as comment):
A problem occurred configuring project ':hellocharts-library'.
Exception thrown while executing model rule: org.gradle.api.publish.plugins.PublishingPlugin$Rules#addConfiguredPublicationsToProjectPublicationRegistry(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectPublicationRegistry, org.gradle.api.publish.PublishingExtension, org.gradle.api.internal.project.ProjectIdentifier)
java.lang.NullPointerException (no error message)
I found solution.

Categories

Resources