Categories
discuss

Android Instant Run Gradle Experimental Plugin

I am encountering the following issue:

file or directory'/Users/rpurohit/Documents/StudioProjects/myapp/app/src/androidTest/manifest', not found
file or directory '/Users/rpurohit/Documents/StudioProjects/myapp/app/src/debug/manifest', not found
file or directory '/Users/rpurohit/Documents/StudioProjects/myapp/app/src/main/manifest', not found
file or directory '/Users/rpurohit/Documents/StudioProjects/myapp/app/src/release/manifest', not found
file or directory '/Users/rpurohit/Documents/StudioProjects/myapp/app/src/test/manifest', not found
FAILURE: Build failed with an exception.

What went wrong:
A problem occurred configuring project ':app'.
Exception thrown while executing model rule: BaseComponentModelPlugin.Rules#createBinaryTasks
Exception thrown while executing model rule: BaseComponentModelPlugin.Rules#createBinaryTasks > create(generateDebugInstantRunAppInfo)
      java.lang.NullPointerException (no error message)

Try:
Run with --debug option to get more log output.

Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
    at org.gradle.execution.TaskNameResolver.selfClosedTasksNode(TaskNameResolver.java:116)
    at org.gradle.execution.TaskNameResolver.hasTask(TaskNameResolver.java:128)
    at org.gradle.execution.TaskNameResolver.selectWithName(TaskNameResolver.java:66)
    at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:87)
    at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:75)
    at org.gradle.execution.commandline.CommandLineTaskParser.parseTasks(CommandLineTaskParser.java:42)
    at org.gradle.execution.TaskNameResolvingBuildConfigurationAction.configure(TaskNameResolvingBuildConfigurationAction.java:44)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:48)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.access$000(DefaultBuildConfigurationActionExecuter.java:25)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter$1.proceed(DefaultBuildConfigurationActionExecuter.java:54)
    at org.gradle.execution.DefaultTasksBuildExecutionAction.configure(DefaultTasksBuildExecutionAction.java:44)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:48)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.access$000(DefaultBuildConfigurationActionExecuter.java:25)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter$1.proceed(DefaultBuildConfigurationActionExecuter.java:54)
    at org.gradle.execution.ExcludedTaskFilteringBuildConfigurationAction.configure(ExcludedTaskFilteringBuildConfigurationAction.java:47)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:48)
    at org.gradle.execution.DefaultBuildConfigurationActionExecuter.select(DefaultBuildConfigurationActionExecuter.java:36)
    at org.gradle.initialization.DefaultGradleLauncher$3.run(DefaultGradleLauncher.java:143)
    at org.gradle.internal.Factories$1.create(Factories.java:22)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:140)
    at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:99)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:93)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:93)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:82)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:94)
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:46)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:58)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:43)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:77)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:47)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:52)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:66)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.model.internal.core.ModelRuleExecutionException: Exception thrown while executing model rule: BaseComponentModelPlugin.Rules#createBinaryTasks
    at org.gradle.model.internal.registry.DefaultModelRegistry.fireAction(DefaultModelRegistry.java:473)
    at org.gradle.model.internal.registry.DefaultModelRegistry.access$1500(DefaultModelRegistry.java:44)
    at org.gradle.model.internal.registry.DefaultModelRegistry$RunModelAction.apply(DefaultModelRegistry.java:1490)
    at org.gradle.model.internal.registry.DefaultModelRegistry.transitionTo(DefaultModelRegistry.java:361)
    at org.gradle.model.internal.registry.DefaultModelRegistry.transition(DefaultModelRegistry.java:439)
    at org.gradle.model.internal.registry.DefaultModelRegistry.atStateOrMaybeLater(DefaultModelRegistry.java:182)
    at org.gradle.model.internal.registry.DefaultModelRegistry.atStateOrLater(DefaultModelRegistry.java:174)
    at org.gradle.execution.TaskNameResolver.selfClose(TaskNameResolver.java:101)
    at org.gradle.execution.TaskNameResolver.selfClosedTasksNode(TaskNameResolver.java:114)
    ... 65 more
Caused by: org.gradle.model.internal.core.ModelRuleExecutionException: Exception thrown while executing model rule: BaseComponentModelPlugin.Rules#createBinaryTasks > create(generateDebugInstantRunAppInfo)
    at org.gradle.model.internal.registry.DefaultModelRegistry.fireAction(DefaultModelRegistry.java:473)
    at org.gradle.model.internal.registry.DefaultModelRegistry.access$1500(DefaultModelRegistry.java:44)
    at org.gradle.model.internal.registry.DefaultModelRegistry$RunModelAction.apply(DefaultModelRegistry.java:1490)
    at org.gradle.model.internal.registry.DefaultModelRegistry.transitionTo(DefaultModelRegistry.java:361)
    at org.gradle.model.internal.registry.DefaultModelRegistry.transition(DefaultModelRegistry.java:439)
    at org.gradle.model.internal.registry.DefaultModelRegistry.access$900(DefaultModelRegistry.java:44)
    at org.gradle.model.internal.registry.DefaultModelRegistry$ModelElementNode.ensureAtLeast(DefaultModelRegistry.java:899)
    at org.gradle.model.internal.registry.DefaultModelRegistry$ModelElementNode.ensureUsable(DefaultModelRegistry.java:894)
    at org.gradle.model.internal.core.NodeBackedModelMap.get(NodeBackedModelMap.java:257)
    at org.gradle.model.internal.core.ModelMapGroovyDecorator.get(ModelMapGroovyDecorator.java:100)
    at com.android.build.gradle.model.TaskModelMapAdaptor.named(TaskModelMapAdaptor.java:71)
    at com.android.build.gradle.internal.scope.AndroidTask.get(AndroidTask.java:170)
    at com.android.build.gradle.internal.ApplicationTaskManager.createIncrementalSupportTasks(ApplicationTaskManager.java:296)
    at com.android.build.gradle.internal.TaskManager.createPostCompilationTasks(TaskManager.java:1905)
    at com.android.build.gradle.internal.ApplicationTaskManager$9.call(ApplicationTaskManager.java:180)
    at com.android.build.gradle.internal.ApplicationTaskManager$9.call(ApplicationTaskManager.java:169)
    at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:55)
    at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:47)
    at com.android.build.gradle.internal.ApplicationTaskManager.createTasksForVariantData(ApplicationTaskManager.java:168)
    at com.android.build.gradle.internal.VariantManager.createTasksForVariantData(VariantManager.java:450)
    at com.android.build.gradle.model.BaseComponentModelPlugin$Rules$8.execute(BaseComponentModelPlugin.java:606)
    at com.android.build.gradle.model.BaseComponentModelPlugin$Rules$8.execute(BaseComponentModelPlugin.java:602)
    at org.gradle.internal.Actions$FilteredAction.execute(Actions.java:202)
    at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:110)
    at org.gradle.api.internal.DefaultDomainObjectCollection.withType(DefaultDomainObjectCollection.java:120)
    at com.android.build.gradle.model.BaseComponentModelPlugin$Rules.createBinaryTasks(BaseComponentModelPlugin.java:602)
    at org.gradle.model.internal.method.WeaklyTypeReferencingMethod.invoke(WeaklyTypeReferencingMethod.java:105)
    at org.gradle.model.internal.inspect.DefaultModelRuleInvoker.invoke(DefaultModelRuleInvoker.java:37)
    at org.gradle.model.internal.inspect.MethodBackedModelAction.execute(MethodBackedModelAction.java:43)
    at org.gradle.model.internal.core.AbstractModelActionWithView.execute(AbstractModelActionWithView.java:46)
    at org.gradle.model.internal.registry.DefaultModelRegistry$2.run(DefaultModelRegistry.java:468)
    at org.gradle.model.internal.registry.RuleContext.run(RuleContext.java:59)
    at org.gradle.model.internal.registry.DefaultModelRegistry.fireAction(DefaultModelRegistry.java:465)
    ... 73 more
Caused by: java.lang.NullPointerException
    at com.android.build.gradle.tasks.fd.GenerateInstantRunAppInfoTask$ConfigAction.execute(GenerateInstantRunAppInfoTask.java:234)
    at com.android.build.gradle.tasks.fd.GenerateInstantRunAppInfoTask$ConfigAction.execute(GenerateInstantRunAppInfoTask.java:204)
    at org.gradle.model.internal.core.NoInputsModelAction.execute(NoInputsModelAction.java:39)
    at org.gradle.model.internal.core.AbstractModelActionWithView.execute(AbstractModelActionWithView.java:46)
    at org.gradle.model.internal.registry.DefaultModelRegistry$2.run(DefaultModelRegistry.java:468)
    at org.gradle.model.internal.registry.RuleContext.run(RuleContext.java:59)
    at org.gradle.model.internal.registry.DefaultModelRegistry.fireAction(DefaultModelRegistry.java:465)
    ... 105 more

I am trying to use Instant Run with the gradle experimental 0.6.0-alpha1 plugin, with gradle 2.9. Whenever I try to build my project, the above stack trace appears. I am using Android Studio 2.0 Preview. Please also note that if I uncheck the ‘Use Instant Run’ checkbox under Android Studio > Preferences > Build, Execution, and Deployment > Instant Run, the build succeeds. I want to use Instant Run.

How can I resolve this issue?

Thanks in advance.

Answer

It is a known issue that Instant Run doesn’t currently work with the Experimental plug-in. You can follow this issue here.

Categories
discuss

Invalid JAVA_HOME when build with cordova

I am trying to emulate an app on my device with cordova in OpenSuse Leap 42.1.
But when I tried to emulate the app with the cordova run I get the error below:

cordova run
Running command: /home/soufraz/Projects/apps/myproject/platforms/android/cordova/run 
ERROR: Error: Failed to run "java -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: /usr/lib64/jvm/java-1.8.0-openjdk-1.8.0

ERROR running one or more of the platforms: Error: /home/soufraz/Projects/apps/myproject/platforms/android/cordova/run: Command failed with exit code 2
You may not have the required environment or OS to run this project

I have the java installed and the paths set in ~/.profile.
Which is the configuration error in my environment?

Below my .profile:

JAVA_HOME=/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0
export JAVA_HOME

ANDROID_HOME=/home/soufraz/Install/android-sdk-linux
export ANDROID_HOME

PATH=$PATH:$ANDROID_HOME:$JAVA_HOME

Info about java version:

java -version
openjdk version "1.8.0_60"
OpenJDK Runtime Environment (build 1.8.0_60-b27)
OpenJDK 64-Bit Server VM (build 25.60-b23, mixed mode)

And here the list of jvm folder:

ls -l
total 28
lrwxrwxrwx 1 root root 24 Nov 12 11:28 java-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0
drwxr-xr-x 1 root root  6 Nov 12 11:28 java-1.7.0-openjdk-1.7.0
drwxr-xr-x 1 root root  6 Nov 11 17:26 java-1.8.0-openjdk-1.8.0
lrwxrwxrwx 1 root root 21 Nov 11 17:26 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root 27 Nov 12 11:28 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx 1 root root 28 Nov 12 11:28 jre-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0/jre
lrwxrwxrwx 1 root root 27 Nov 11 17:26 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx 1 root root 28 Nov 11 17:26 jre-1.8.0-openjdk -> java-1.8.0-openjdk-1.8.0/jre
lrwxrwxrwx 1 root root 29 Nov 11 17:26 jre-openjdk -> /etc/alternatives/jre_openjdk

[edit] View tree with three levels:

tree -L 3
.
├── java-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0
├── java-1.7.0-openjdk-1.7.0
│   └── jre
│       ├── bin
│       └── lib
├── java-1.8.0-openjdk-1.8.0
│   └── jre
│       ├── bin
│       └── lib
├── jre -> /etc/alternatives/jre
├── jre-1.7.0 -> /etc/alternatives/jre_1.7.0
├── jre-1.7.0-openjdk -> java-1.7.0-openjdk-1.7.0/jre
├── jre-1.8.0 -> /etc/alternatives/jre_1.8.0
├── jre-1.8.0-openjdk -> java-1.8.0-openjdk-1.8.0/jre
└── jre-openjdk -> /etc/alternatives/jre_openjdk

Answer

In my specific case, I remove and reinstall all java packages and add one (for ‘instinct’):
I removed:
java-1_8_0-openjdk
java-1_8_0-openjdk-headless
java-1_8_0-openjdk-plugin

And added:
java-1_8_0-openjdk
java-1_8_0-openjdk-headless
java-1_8_0-openjdk-plugin
java-1_8_0-openjdk-devel <<– luckily I hit it

The bin inside main folder appears. With javac and another things.
Thank you guys!

Categories
discuss

Android Resource issues after upgrading to Xamarin Forms 2.0

I have recently upgraded 2 machines from Xamarin Forms 1.x to 2.0. One machine is OK and Xamarin Forms projects build fine for Android. The other machine is having dreadful issues.

We have tried uninstalling and re-installing everything – Xamarin, Android SDK, all NuGet packages – the lot – but get the same error messages.

It seems to be related to Android app compat stuff.

Steps to replicate are:

  1. Create new Forms 1.3 project – compile and run – all OK
  2. Upgrade project from Forms 1.3 to 2.0 – issues

Here are the errors:

2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1290,119,1290,143): error CS0117: 'Resource.Styleable' does not contain a definition for 'SnackbarLayout_elevation'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1291,130,1291,165): error CS0117: 'Resource.Styleable' does not contain a definition for 'SnackbarLayout_maxActionInlineWidth'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1308,104,1308,113): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1309,118,1309,141): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabBackground'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1310,120,1310,145): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabContentStart'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1311,115,1311,135): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabGravity'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1312,122,1312,149): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabIndicatorColor'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1313,123,1313,151): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabIndicatorHeight'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1314,116,1314,137): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabMaxWidth'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1315,116,1315,137): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabMinWidth'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1316,112,1316,129): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabMode'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1317,115,1317,135): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabPadding'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1318,121,1318,147): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabPaddingBottom'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1319,118,1319,141): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabPaddingEnd'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1320,120,1320,145): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabPaddingStart'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1321,118,1321,141): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabPaddingTop'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1322,125,1322,155): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabSelectedTextColor'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1323,122,1323,149): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabTextAppearance'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1324,117,1324,139): error CS0117: 'Resource.Styleable' does not contain a definition for 'TabLayout_tabTextColor'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1331,110,1331,125): error CS0117: 'Resource.Styleable' does not contain a definition for 'TextInputLayout'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1332,123,1332,151): error CS0117: 'Resource.Styleable' does not contain a definition for 'TextInputLayout_android_hint'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1333,132,1333,169): error CS0117: 'Resource.Styleable' does not contain a definition for 'TextInputLayout_android_textColorHint'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1334,123,1334,151): error CS0117: 'Resource.Styleable' does not contain a definition for 'TextInputLayout_errorEnabled'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1335,130,1335,165): error CS0117: 'Resource.Styleable' does not contain a definition for 'TextInputLayout_errorTextAppearance'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1336,131,1336,167): error CS0117: 'Resource.Styleable' does not contain a definition for 'TextInputLayout_hintAnimationEnabled'
2>d:DocumentsVisual Studio 2015ProjectsApp4App4App4.DroidResourcesResource.Designer.cs(1337,129,1337,163): error CS0117: 'Resource.Styleable' does not contain a definition for 'TextInputLayout_hintTextAppearance'

Answer

Delete everything inside your Resource.Designer.cs file (not the file itself) and rebuild. It should regenerate the file for you and the errors will disappear.

First next step

Make sure your Google support packages are all at 23.0.1.3. Thats a requirement for XF 2.0 but they should have been updated with the XF 2.0 upgrade.

When all else is failing (copied across from my answer to another question)

1. Clean solution
2. update-package -reinstall (can use -project just for your Android project)
3. Delete Resource.Designer.cs contents again
4. Restart Visual Studio
5. Rebuild once again

You might also want to add sobbing, praying or cursing in with those steps 🙂

One final thing, if that doesn’t work, try the same again but this time uninstalling all NuGet packages and components instead of a reinstall. That has worked for me before.

Then make sure your cache’s are clean (C:UsersyourusernameAppDataLocalXamarin). I normally delete everything in here so it can rebuild them.

I have unfortunately had to do everything listed above before to get the Resource.Designer.cs to work in previous occasions.

Categories
discuss

Struggling with JDBC in Android Studio

I’m trying to run a stored procedure on my SQL Server database from an Android app I’ve developed. I’m just messing about at the minute but I can’t seem to get it to run. Thing is I don’t get any kind of errors or crashes either – the app works fine and I can click the button, the stored procedure just doesn’t seem to want to run.

The SP creates a row in a table. I’ve tested this in SQL server and it works perfectly. The issue seems to be with executing it from my app..

I think I’ve set things up correctly.

1) I’ve included the correct .jar file in the libs folder for my app.

2) I’ve included a reference to the library in build.gradle:-

dependencies {
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/jtds-1.3.1.jar')
}

3) I’ve imported all of the libraries that I need (I think):-

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

4) I’ve got a button that, when clicked should run the stored procedure:-

@Override
public void onClick(View v) {
    try {
        Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
        String username = "myusername";
        String password = "mypassword";
        Connection DbConn = DriverManager.getConnection("jdbc:jtds:sqlserver://sql9.hostinguk.net/matprichardson;user=" + username + ";password=" + password);

        Log.w("Connection","Open");
        Statement stmt = DbConn.createStatement();
        stmt.execute("exec [matprichardson].[updatelatlong]");

        DbConn.close();
    } catch (Exception e) {
        Log.w("Error connection","" + e.getMessage());
    }
}

If I remove the code from the try/catch blocks, the Class.forName part highlights in red and when I hover I get a java.lang.ClassNotFoundException but I’ve read that’s the reason for the try/catch block in the first place…am I right?

Anyway, after tinkering about with this for an hour I’ve reached a point where I don’t know what to do anymore. Hope you guys can help.

Note: I’m running the app directly on my device rather than through an emulator.

Another note: In the ‘logcat’ part of Android Monitor I get an error. Full log when I click the button:

11-28 22:54:29.173 11995-11995/uk.co.matprichardson.omgandroid D/libc: [NET] android_getaddrinfofornet+,hn 18(0x73716c372e686f),sn(),hints(known),family 0,flags 4
11-28 22:54:29.173 11995-11995/uk.co.matprichardson.omgandroid D/libc: [NET] android_getaddrinfofornet-, err=8
11-28 22:54:29.173 11995-11995/uk.co.matprichardson.omgandroid E/MYAPP: exception android.os.NetworkOnMainThreadException
    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1155)
    at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
    at java.net.InetAddress.getAllByName(InetAddress.java:215)
    at java.net.Socket.tryAllAddresses(Socket.java:109)
    at java.net.Socket.<init>(Socket.java:178)
    at java.net.Socket.<init>(Socket.java:150)
    at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:259)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:311)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:187)
    at java.sql.DriverManager.getConnection(DriverManager.java:179)
    at java.sql.DriverManager.getConnection(DriverManager.java:144)
    at uk.co.matprichardson.omgandroid.MainActivity.onClick(MainActivity.java:114)
    at android.view.View.performClick(View.java:4785)
    at android.view.View$PerformClick.run(View.java:19869)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:155)
    at android.app.ActivityThread.main(ActivityThread.java:5721)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)

Answer

This is not entirely right.

catch (Exception e)
{
    Log.w("Error connection","" + e.getMessage());
}
11-26 20:49:14.662 5445-5445/uk.co.matprichardson.omgandroid W/Error connection: null

As usual, the answer is in the full stack trace, not in only the exception message. You’re basically suppressing the whole exception including its stack trace and only logging the sole exception message. This is really unhelpful (not only for us in order to translate it into layman’s terms in case you didn’t understand it, but also for yourself in order to research/google it).

In case you have no idea how to print the full stack trace in Android, head to among others the following Q&A: Android – print full exception backtrace to log.

Once having the full stack trace at hands which should look like below:

android.os.NetworkOnMainThreadException
    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1155)
    at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
    at java.net.InetAddress.getAllByName(InetAddress.java:215)
    at java.net.Socket.tryAllAddresses(Socket.java:109)
    at java.net.Socket.<init>(Socket.java:178)
    at java.net.Socket.<init>(Socket.java:150)
    at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:259)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:311)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:187)
    at java.sql.DriverManager.getConnection(DriverManager.java:179)
    at java.sql.DriverManager.getConnection(DriverManager.java:144)
    at uk.co.matprichardson.omgandroid.MainActivity.onClick(MainActivity.java:114)
    at android.view.View.performClick(View.java:4785)
    at android.view.View$PerformClick.run(View.java:19869)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:155)
    at android.app.ActivityThread.main(ActivityThread.java:5721)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)

Then simply copypaste the exception type, message (if any) and 1st line of stack trace (without the parentheses and line number), like below,

android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork

Into a decent search engine for clues, like Google. As of now, the top hits directly or indirectly (duplicate) refer the below Stack Overflow questions:

Surely one of them must have explained/answered your concrete problem.

Categories
discuss

Iterate over values of object

I want to iterate over all values of a map. I know it’s possible to iterate over all keys. But is it possible to iterate directly over the values?

 var map = { key1 : 'value1', key2 : 'value2' }
 for (var key in map) { ...} // iterates over keys

Answer

It’s not a map. It’s simply an Object.

Edit: below code is worse than OP’s, as Amit pointed out in comments.

You can “iterate over the values” by actually iterating over the keys with:

var value;
Object.keys(map).forEach(function(key) {
    value = map[key];
    console.log(value);
});
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..