R file not generated for androidTests when using AGP 4.2.0 or 7.0 - android-gradle-plugin

I have tried migrating to a new Gradle Plugin, but since we have some custom layouts for AndroidTests, it fails with an error saying "R class was not found" for the android tests.
I could not find any source saying about any behaviour changes in this area.
The error looks like this and seems to be related to view inding or simply to the fact the R class is not generated.
/pathToTheApp/build/generated/data_binding_base_class_source_out/debugAndroidTest/out/com/package1/test/databinding/CustomViewActivityBinding.java:12: error: cannot find symbol
import package.name.test.R;
^
symbol: class R
location: package package.name.test

I had this problem in our Android tests after upgrading to AGP 7.0. Our test R class could not be found. I managed to fix it by duplicating the testApplicationId into the seemingly new testNamespace field.
android {
testNamespace = "com.example.tests"
defaultConfig {
testApplicationId "com.example.tests"
}
}
I think it should work without it, so maybe this is a plugin bug, but the docs say:
The namespace used by the android test and unit test components for the generated R and BuildConfig classes

Related

setting up ACRA 5.5.1 in ReactNative 0.61.2

I am trying to setup ACRA for my react native project which using 0.61.2 version. I followed the basic setup tutorial from https://github.com/ACRA/acra/wiki/BasicSetup .
But while building the project I got errors
/android/app/src/main/java/com/agentnativeapp/MainApplication.java:36: error: cannot find symbol
CoreConfigurationBuilder builder = new CoreConfigurationBuilder(this)
^
symbol: class CoreConfigurationBuilder
location: class MainApplication
I don't understand what am I missing. I thought I might be missing the jar file, but there are no instructions showing the requirement of jar file.
I am new to JAVA side of programming so I am new to all these jar stuff
Turns out it was all importing problem.
import org.acra.;
import org.acra.annotation.;
The above statement doesn't actually import every class, so I have to CoreConfigurationBuilder separately
import org.acra.config.CoreConfigurationBuilder;

IntelliJ shows unresolved reference to java.lang.String#replace in Fabric Kotlin dev environment

class Foo(
val name: Identifier,
val trKey: String = "action.${name.toString().replace(':', '.')}"
// ^~~~~~~ this is unresolved
) {
// Members
}
The replace function is able to be resolved in Fabric's source code and it does run, but it doesn't in my Kotlin code.
I've tried setting the project SDK to 1.8, 11, and Kotlin SDK, and none of them seem to solve this issue. In fact, putting the SDK to 11 makes java.lang.String inaccesible.
I think I fixed it by adding KotlinRuntime into libraries through IntelliJ project structure (will get erased by Gradle import), or with gradle dependencies adding Kotlin library.
Instead I found changing JDK version back to 1.8 fixes this issue and is reproducable. The above only worked once for me.

Instant app with multivariant base module

I've started to implement instant app feature in my application. I managed to transition to base module and properly build an installable app. The base module has 3 build types:
buildTypes {
release {...}
acceptance {...}
debug {...}
When I try to build instant app as a separate module that has build.gradle file:
apply plugin: 'com.android.instantapp'
dependencies {
implementation project(':base')
}
I'm getting below error message:
Cannot choose between the following variants of project :app:
- inchargeAcceptanceBundleElements
- inchargeAcceptanceRuntime
- inchargeAcceptanceUnitTestCompile
...
(much much longer I can give full stacktrace if needed)
I tried to change instantapp/build.gradle:
implementation project(path: ':base', configuration: 'default')
but then I get:
Unable to resolve dependency for ':instantapp#debug/compileClasspath': Failed to transform file 'base-release.aar' to match attributes {artifactType=processed-aar} using transform IdentityTransform
Then the app module itself has 4 product flavors but it shouldn't matter I believe.
Any advice how to run instantapp module ?

Kotlin - Error: Could not find or load main class _DefaultPackage

I followed the Kotlin tutorial for eclipse here : Getting Started With Eclipse Luna
However, I'm running into this error:
Error: Could not find or load main class _DefaultPackage
Anyone who knows to get around this?
This was a severe bug (KT-10221) in automatic generation of Launch Configuration in plugin version 0.4.0. It was fixed in 0.5.0 so the recommendend way to workaround is to update plugin.
The source of the problem was that the plugin used an old pattern for generating name of the class for main function that had been abandoned by Kotlin compiler.
It's possible to workaround it by editing launch configuration (Eclipse Menu -> Run -> Run Configurations...) by hand and changing Main class field in Java Application group. If the file is named hello.kt with no package directive, as it is described in tutorial, than corrected string should be HelloKt.
If file has name other.kt with package my.tutorial than the Main Class should contain my.tutorial.HelloKt. You can read more about it in the section Package-Level Functions of Calling Kotlin From Java page.
I have been getting the same issue. And after putting the right compiler output path, it got resolved.
Go to Project -> Project Compiler output :
In the text box, fill this:
[Absolute Path]/{Project Name}/out
In my case I was having this problem while trying to run the program using the Application Gradle plugin. The problem was in the mainClassName property using single quotes instead of double ones
This didn't work:
mainClassName = 'demo.HelloWorldKt'
With double quotes, it works:
mainClassName = "demo.HelloWorldKt"
For me it worked after I installed the correct JDK. I first had JDK 11 but the tutorial I did was with JDK 8 so after I installed this and set it in the "installed JREs" options it found the main class without having any "mainClassName" or any other option in the build.gradle file.
For me, it worked in a fresh eclipse workspace. Possibly, the Kotlin eclipse plugin is not playing well with other plugins (in my case, PyDev).
I'm creating a Kotlin Application with JavaFX and I had this issue until I went to:
Run > Run Configurations > Java Application > Common
I unticked "Allocate console" and it fixed the issue.

TeamCity - Testing with JUnit

I am using Intellij Idea version 12 (ultimate). Just installed Team City (version 8). One default agent, running in linux.
I've created a very simple test application:
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
public int sum(int x, int y) {
return x+y;
}
}
... and a very simple test...
import junit.framework.Assert;
import org.junit.Test;
public class MainTest {
#Test
public void testSum() throws Exception {
Main test=new Main();
Assert.assertEquals("Sum should be 7",7,test.sum(4,4));
}
}
If I run this in IntelliJ, the test gets run and fails just like it should.
If instead I commit this project and push it up to github, TeamCity sees the change and begins a build. The build fails fairly quickly with the following errors:
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:1: package junit.framework does not exist
import junit.framework.Assert;
^
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:2: package org.junit does not exist
import org.junit.Test;
^
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:12: cannot find symbol
symbol : class Test
location: class MainTest
#Test
^
/home/ctb/TeamCity/buildAgent/work/742505fa88794219/test/MainTest.java:15: cannot find symbol
symbol : variable Assert
location: class MainTest
Assert.assertEquals("Sum should be 7. Loser!!",7,test.sum(4,4));
^
So yeah, I see that TeamCity is not seeing JUnit.
On the TeamCity Discussion forum, one respondent to my question there asked me if junit.jar was added as a dependency (module or library) in the build. It was listed as a module dependency, but for kicks I tried it as a library dependency. I also tried checking and unchecking export and trying the compile and test scopes, but each time I get the same errors. My run configuration is shared.
I am not using Ant or Maven. Perhaps someday, but I'd like to start as simple as possible.
Clearly, I'm missing something, but the documentation on the subject is sparse.
Thank you.
So I heard back from Jetbrains tech support this and, in the interest of completeness and saving someone else the trouble, here's the response I received:
Seems the problem is that junit.jar is not placed in version control
under your project. In order to build your project on TeamCity agent,
the project ideally should be self contained. In your case junit.jar
only exists on your local machine, I suppose there is no such file on
agent at required location. So you have two options actually: put
junit.jar under version control into your project, or define global
library in IDEA and configure this global library on IDEA Project
runner page (Check/Reparse must be started), after that put library
files on all of the agents where your build will be executed.
Personally, I think the first approach is much simpler and better.
I added junit to version control and now the build works properly in TeamCity.